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 / December 2005

Tip: Looking for answers? Try searching our database.

Bookmarks in header

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
zamdrist@gmail.com - 27 Dec 2005 15:32 GMT
Having troubles changing my Selection to a bookmark in a header. Here's
what I tried:

With objDocument
If .Bookmarks.Exists("Applicant1") = True Then
 .ActiveWindow.View.Type = wdPrintView
 .ActiveWindow.View.SeekView = wdSeekCurrentPageHeader
 .ActiveWindow.ActivePane.Selection.GoTo wdGoToBookmark, , ,
"Applicant1"
 .ActiveWindow.ActivePane.Selection.InsertAfter txtApplicant.Value
End If
End With

Although the bookmark exists, I still get an error that it does not,
presumably not in the 'view' it's looking for it in. I've stepped
though the code and watched the document's view change to show the
header, but once it tries to change the selection to the bookmark found
in the header, the header closes...and therefore it cannot find the
bookmark.

Ideas? Thoughts? Ridicule? :)

Thanks!
Jay Freedman - 27 Dec 2005 17:02 GMT
>Having troubles changing my Selection to a bookmark in a header. Here's
>what I tried:
[quoted text clipped - 19 lines]
>
>Thanks!

The main idea is that when using VBA, selections and views and headers
don't mix very well. Instead, use a Range object and the Headers
collection, something like this:

   Dim oRg As Range
   
   With objDocument.Sections(1).Headers( _
           wdHeaderFooterPrimary).Range
       If .Bookmarks.Exists("Applicant1") Then
           Set oRg = .Bookmarks("Applicant1").Range
           oRg.Text = txtApplicant.Value
           .Bookmarks.Add Name:="Applicant1", Range:=oRg
       End If
   End With

If the document has more than one section, or if the bookmark is in a
first-page or even-page header, you'd need to make some adjustments.

The reason for using .Bookmarks.Add to make sure the bookmark covers
the inserted text is explained at
http://www.word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
strazz@my-Deja.com - 27 Dec 2005 23:19 GMT
Use objDocument .Bookmarks("Applicant1").select instead.

Cheers
TonyS.
zamdrist@gmail.com - 29 Dec 2005 03:58 GMT
Thank you TonyS & Jay...selecting the bookmark did the trick!

Have a great New Year! :)

Steve

> Use objDocument .Bookmarks("Applicant1").select instead.
>
> Cheers
> TonyS.
 
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.