Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

Userform causing document view/layout to change

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Per Axbom - 07 Oct 2005 14:20 GMT
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?
Jonathan West - 07 Oct 2005 18:29 GMT
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?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.