Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
I use word 2003 sp3
I made a dot file with merge fields and bookmarks. When I open the dot file a new file is created but the bookmarks are gone and the mergefield regonise is gone only the value is left. I need to retrieve with vba the value that is in a certain mergefield. Any suggestion is welcome. |
#2
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
After executing a merge, the mergefields are converted to normal text,
displaying the data that was contained in that field in the data source. In the case of the bookmarks, they will not survive the execution of the merge because each bookmark must have a unique name and if the merge was executed to a new document and the bookmarks were to be retained, there would be mutlitple instances of bookmarks trying to assume the same name. The following macro will "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 "Lodewijk" wrote in message ... I use word 2003 sp3 I made a dot file with merge fields and bookmarks. When I open the dot file a new file is created but the bookmarks are gone and the mergefield regonise is gone only the value is left. I need to retrieve with vba the value that is in a certain mergefield. Any suggestion is welcome. |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Word 2007 bookmarks - How to display bookmarks on page? | Microsoft Word Help | |||
Mergefield statement help | Mailmerge | |||
MergeField | Mailmerge | |||
Using IF with MERGEFIELD | Mailmerge | |||
OR in a mergefield? | Mailmerge |