Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
sanjeev sanjeev is offline
external usenet poster
 
Posts: 4
Default how to preserve the bookmark while using mailmerge feature

Hi Robins,

Thanks a lot , It solved my problem

Regards
Sanjeev

"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

Source.Activate
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
Loop
End With


--
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

"sanjeev" wrote in message
...
Hi,

I have a word document which contains many bookmarks , after using the
'Mail merge' feature the bookmarks are removed, Is there a way to solve
it.

Thanks in Advance




 
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
My noteref to valid bookmark says "Error! Bookmark not defined."? jchilders_98 Microsoft Word Help 3 October 5th 06 02:23 PM
The Insert Bookmark box shouldnt vanish after adding a bookmark. RogerKni Microsoft Word Help 4 September 26th 06 03:13 PM
How to use mailmerge feature to generate report? (i.e. SQL statem will~ Mailmerge 1 April 11th 06 09:25 AM
Word should preserve cycles of track changes Doug at PBS&J Microsoft Word Help 1 January 18th 06 05:10 PM
Preserve Formatting of TOC Ted Microsoft Word Help 11 January 26th 05 03:49 PM


All times are GMT +1. The time now is 07:19 AM.

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

About Us

"It's about Microsoft Word"