#1   Report Post  
Posted to microsoft.public.word.docmanagement
kyle''s kyle''s is offline
external usenet poster
 
Posts: 11
Default Bookmarks & Merging

I have a merge document that I need to preserve my bookmarks. We a merge is
performed, the bookmarks are stripped away. Is there a way of preserving the
bookmarks?

Any help would be greatly appreciated.
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Bookmarks & Merging

' Throwaway Macro created by Doug Robbins to "preserve" bookmarks during a
MailMerge
'
Dim abm As Bookmark, bmrange As Range, i As Long, Result As Document, j As
Long, k As Long, linkrange As Range, linktarget As String
Dim Source As Document
Set Source = ActiveDocument
i = 1
For j = 1 To Source.MailMerge.DataSource.RecordCount
For Each abm In ActiveDocument.Range.Bookmarks
System.PrivateProfileString("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name & Format(j)
i = i + 1
Next
Next j
For Each abm In ActiveDocument.Range.Bookmarks
abm.Range.InsertBefore "#"
abm.Range.InsertAfter "#"
Next
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Set Result = ActiveDocument
k = 1
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="#*#", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=True) = True
Set bmrange = Selection.Range
bmrange.Characters(bmrange.Characters.Count).Delet e
bmrange.Characters(1).Delete
Result.Bookmarks.Add System.PrivateProfileString("c:\bookmarks.txt",
"bookmarkNames", "bookmark" & k), bmrange
k = k + 1
Loop
End With
For i = 1 To Result.Hyperlinks.Count
linktarget = Result.Hyperlinks(i).SubAddress
Set linkrange = Result.Hyperlinks(i).Range
linkrange.Select
linktarget = linktarget &
Format(Selection.Information(wdActiveEndSectionNum ber))
Result.Hyperlinks.Add Result.Hyperlinks(i).Range, "", linktarget
Next i

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"kyle''s" wrote in message
...
I have a merge document that I need to preserve my bookmarks. We a merge
is
performed, the bookmarks are stripped away. Is there a way of preserving
the
bookmarks?

Any help would be greatly appreciated.



  #3   Report Post  
Posted to microsoft.public.word.docmanagement
kyle''s kyle''s is offline
external usenet poster
 
Posts: 11
Default Bookmarks & Merging

Thank you Doug, much appreciated!

"Doug Robbins - Word MVP" wrote:

' Throwaway Macro created by Doug Robbins to "preserve" bookmarks during a
MailMerge
'
Dim abm As Bookmark, bmrange As Range, i As Long, Result As Document, j As
Long, k As Long, linkrange As Range, linktarget As String
Dim Source As Document
Set Source = ActiveDocument
i = 1
For j = 1 To Source.MailMerge.DataSource.RecordCount
For Each abm In ActiveDocument.Range.Bookmarks
System.PrivateProfileString("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name & Format(j)
i = i + 1
Next
Next j
For Each abm In ActiveDocument.Range.Bookmarks
abm.Range.InsertBefore "#"
abm.Range.InsertAfter "#"
Next
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Set Result = ActiveDocument
k = 1
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="#*#", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=True) = True
Set bmrange = Selection.Range
bmrange.Characters(bmrange.Characters.Count).Delet e
bmrange.Characters(1).Delete
Result.Bookmarks.Add System.PrivateProfileString("c:\bookmarks.txt",
"bookmarkNames", "bookmark" & k), bmrange
k = k + 1
Loop
End With
For i = 1 To Result.Hyperlinks.Count
linktarget = Result.Hyperlinks(i).SubAddress
Set linkrange = Result.Hyperlinks(i).Range
linkrange.Select
linktarget = linktarget &
Format(Selection.Information(wdActiveEndSectionNum ber))
Result.Hyperlinks.Add Result.Hyperlinks(i).Range, "", linktarget
Next i

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"kyle''s" wrote in message
...
I have a merge document that I need to preserve my bookmarks. We a merge
is
performed, the bookmarks are stripped away. Is there a way of preserving
the
bookmarks?

Any help would be greatly appreciated.




Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 2007 bookmarks - How to display bookmarks on page? rgille Microsoft Word Help 2 April 27th 23 02:55 AM
Bookmarks Noella Microsoft Word Help 1 October 16th 07 12:49 PM
Bookmarks ll Microsoft Word Help 1 March 6th 07 11:32 PM
Can I have more than one set of bookmarks Larry Root Microsoft Word Help 2 February 4th 07 10:30 AM
Bookmarks suinat New Users 0 October 2nd 05 05:01 PM


All times are GMT +1. The time now is 05:39 AM.

Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"