Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Lodewijk Lodewijk is offline
external usenet poster
 
Posts: 4
Default Mergefield and bookmarks

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   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Mergefield and bookmarks

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

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
Mergefield statement help John Mailmerge 6 March 23rd 07 04:48 PM
MergeField Jeff Bergeron Mailmerge 2 February 22nd 07 03:19 PM
Using IF with MERGEFIELD [email protected] Mailmerge 2 June 21st 06 04:17 PM
OR in a mergefield? Compass Rose Mailmerge 2 April 12th 06 06:04 AM


All times are GMT +1. The time now is 08:51 PM.

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"