I have a userform set up to enter data in bookmarks. All that works fine.
My problem is that when the user clicks OK in the Userform then the document
view changes from Print Layout to Normal. I want the user to stay in Print
Layout mode as most users do not know how to change this in their
preferences.
Why is this happening? It started happening when I wanted to set up the
Userform to Replace all text in the Bookmarks instead of entering data in
front of the text in the bookmarks. For this I am using the following code:
Private Sub CommandButton1_Click()
With ActiveDocument
.Bookmarks("Bookmark1").Range.Select
With Selection
.Range.Delete
.Text = TextBox1
.Bookmarks.Add "Bookmark1"
End With
.Bookmarks("Bookmark2").Range.Select
With Selection
.Range.Delete
.Text = TextBox2
.Bookmarks.Add "Bookmark2"
End With
End Width
End Sub
Something in the way I am doing this is affecting the view/layout. Help
anyone?
Hi per,
By any chance, are any of the bookmarks in page headers? If so, selecting in
a header might account for this.
You don't need to select a bookmark, you can manipulate the range directly
using a range object variable, like this
Private Sub CommandButton1_Click()
Dim oRange as range
With ActiveDocument
Set oRange = .Bookmarks("Bookmark1").Range
oRange.Text = TextBox1
.Bookmarks.Add Name:="Bookmark1", Range:=oRange
Set oRange = .Bookmarks("Bookmark2").Range
oRange.Text = TextBox2
.Bookmarks.Add Name:="Bookmark2", Range:=oRange
End With
End Sub

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
>I have a userform set up to enter data in bookmarks. All that works fine.
>
[quoted text clipped - 32 lines]
> Something in the way I am doing this is affecting the view/layout. Help
> anyone?
Per Axbom - 09 Oct 2005 20:58 GMT
Thanx Jonathan, this works like a charm.
> Hi per,
>
[quoted text clipped - 58 lines]
>> Something in the way I am doing this is affecting the view/layout. Help
>> anyone?