Reply
 
Thread Tools Display Modes
  #1   Report Post  
Sue Rizzo
 
Posts: n/a
Default Mailmerge and Bookmarks

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?
  #2   Report Post  
Doug Robbins
 
Posts: n/a
Default

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).Delet e

bmrange.Characters(1).Delete

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

k = k + 1

Loop

End With


--
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
"Sue Rizzo" Sue wrote in message
...
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?



  #3   Report Post  
Sue Rizzo
 
Posts: n/a
Default

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

"Doug Robbins" wrote:

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).Delet e

bmrange.Characters(1).Delete

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

k = k + 1

Loop

End With


--
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
"Sue Rizzo" Sue wrote in message
...
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?




  #4   Report Post  
Doug Robbins
 
Posts: n/a
Default

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.

--
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
"Sue Rizzo" wrote in message
...
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

"Doug Robbins" wrote:

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).Delet e

bmrange.Characters(1).Delete

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

k = k + 1

Loop

End With


--
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
"Sue Rizzo" Sue wrote in message
...
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?






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
Keep form fields after protected mailmerge beabvo Mailmerge 1 January 26th 05 10:13 AM


All times are GMT +1. The time now is 01:54 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"