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 / Mailmerge and Fax / March 2005

Tip: Looking for answers? Try searching our database.

Mailmerge and Bookmarks

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sue Rizzo - 09 Mar 2005 19:39 GMT
I have a mailmerge main doc that contains bookmarks.  When the doc is merge
into the new doc, the bookmarks are gone.  Can anyone tell me how to prevent
the bookmarks from disappearing?
Doug Robbins - 10 Mar 2005 03:12 GMT
The name of each bookmark in a document must be unique, therefore, they
cannot survive the merge process.  Maybe you can make use of the following
macro to "re-create" the bookmarks

' 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).Delete

       bmrange.Characters(1).Delete

       Result.Bookmarks.Add System.PrivateProfileString("c:\bookmarks.txt",
"bookmarkNames", "bookmark" & k), bmrange

       k = k + 1

   Loop

End With

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

>I have a mailmerge main doc that contains bookmarks.  When the doc is merge
> into the new doc, the bookmarks are gone.  Can anyone tell me how to
> prevent
> the bookmarks from disappearing?
Sue Rizzo - 10 Mar 2005 14:59 GMT
Thanks Doug!
It's unfortunate that bookmarks can't survive the merge process, they are
unique within each document (the main and the new) so I'm not sure I
understand the problem with their survival to the new doc.  I do appreciate
the macro though I had trouble with the syntax of 2 lines:  

> For j = 1 To Source.MailMerge.DataSource.RecordCount

.RecordCount is not available so I used .ActiveRecord

and

>         Result.Bookmarks.Add System.PrivateProfileString("c:\bookmarks.txt",
> "bookmarkNames", "bookmark" & k), bmrange

I'm not sure what this is doing, I am a beginner with vb code so I'm not
sure how to correct.  
Thanks for your help!!
Sue

> The name of each bookmark in a document must be unique, therefore, they
> cannot survive the merge process.  Maybe you can make use of the following
[quoted text clipped - 75 lines]
> > prevent
> > the bookmarks from disappearing?
Doug Robbins - 11 Mar 2005 02:50 GMT
You have to have the mailmerge main document with a datasource attached to
it when you run the code.  That should deal with the first issue.

The second is caused by what is a single line of code wrapping in the mail
program.  Remove the carriage return at the end of the first line so that it
is restored to a single line in the Visual Basic Editor.

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> Thanks Doug!
> It's unfortunate that bookmarks can't survive the merge process, they are
[quoted text clipped - 102 lines]
>> > prevent
>> > the bookmarks from disappearing?
 
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.