A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Mailmerge
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Bookmarks are not retained during Mail Merge



 
 
Thread Tools Display Modes
  #11  
Old May 31st, 2004, 07:03 AM
Doug Robbins - Word MVP
external usenet poster
 
Posts: n/a
Default Bookmarks are not retained during Mail Merge

The code worked here. When if finishes running, there should be no # to be
seen as the final thing that it does is delete the #'s that it inserts into
the mailmerge main document. Did you look in your default document location
for a whole lot of files with the filename Letter#.doc? They will be the
ones with the bookmarks in them.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in message
...
Thanks for the code Doug.

While running the macro from main document, message
saying "Word has insufficient memory. You will not be able
to undo this action once it is completed. Do you want to
continue?" appeared twice. I hit Yes. All that's happend
was (1) '#' was inserted before and after the bookmark
range in the main document (2) bookmarks.txt created in C
directory (3) merged document created without any
bookmarks (I couldn't see any # reference in there)

Your help much appreciated.

Regards
Latha


-----Original Message-----
If you run the following macro when the mailmerge main

document is active,
it will execute the merge to a new document, split that

new document into
individual documents with each document corresponding to

a record in the
datasource and then it will recreate the bookmarks that

were in the main
document in each of those documents and save and close

them with a filename
"Letter#" where # is a sequential number:

' 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
Dim Target As Document, Letter As Range, source As

Document
Set source = ActiveDocument
i = 1
For Each abm In ActiveDocument.Range.Bookmarks
System.PrivateProfileString

("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name
abm.Range.InsertBefore "#"
abm.Range.InsertAfter "#"
i = i + 1
Next
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Set Result = ActiveDocument
For j = 1 To Result.Sections.Count - 1
Set Letter = Result.Sections(j).Range
Letter.End = Letter.End - 1
Set Target = Documents.Add
Target.Range = Letter
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
Target.Bookmarks.Add
System.PrivateProfileString

("c:\bookmarks.txt", "bookmarkNames", "bookmark"
& k), bmrange
k = k + 1
Loop
End With
Target.SaveAs FileName:="Letter" & j
Target.Close
Next j
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).Delete
bmrange.Characters(1).Delete
Loop
End With

If your mailmerge maindocument happens to include "#" in

it, replace that
character wherever it appears in the above code with some

other character
that does not appear in the document.
--
Please post any further questions or followup to the

newsgroups for the
benefit of others who may be interested. Unsolicited

questions forwarded
directly to me will only be answered on a paid consulting

basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in

message
...
Doug

Let me try to explain bit more.

For example, I have a bookmark called bookmark1 which
takes to section 4.1 of the main document and another
bookmark I have was, say bookmark2 which takes to

section
1 highlighting the entire text under section 1; And

these
needs to be carried to the merged document.

Hope this helps.

Regards
Latha

-----Original Message-----
Sorry, that does not mean much. What is the purpose of
the links?

--
Please post any further questions or followup to the
newsgroups for the
benefit of others who may be interested. Unsolicited
questions forwarded
directly to me will only be answered on a paid

consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in
message
...
Sorry for not answering your question before, Doug.

The
purpose of the bookmarks is to keep the links from

the
main document. Hope I am clear, if not please let me
know.

Regards
Latha

-----Original Message-----
But what is the purpose of the bookmarks?

--
Please post any further questions or followup to the
newsgroups for the
benefit of others who may be interested.

Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
wrote in

message
...
Thanks for your reply Doug. I wanted to carry over
the
bookmarks from main document to the merged

document;
The
merged document should contain the same bookmarks
from
the
main document. This main document is a template

and
any
merged document should resemble main document.

I am using Excel spreadsheet as data source and
performing
mail merge in Word 2000.

I tried macro code to replace bookmark field with
placeholder in the main document, perform mail

merge
(close main document without saving any changes),
then
in
the merged document replace placeholders with the
bookmark; that worked but the problem is

placeholders
exists in the sense any attempts to delete
placeholder
is
deleting the bookmark.

Please advise. Many thanks in advance.

Regards
Latha

-----Original Message-----
As the name of each bookmark in a document must

be
unique, they are not
retained when you create multiple copies in the
document
as you do when you
execute a mailmerge.

Tell us what the purpose of the bookmarks is and

we
may
be able to tell you
how to do whatever it is in another way.

--
Please post any further questions or followup to

the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"

wrote
in
message
...
Hi

I wanted to know if its possible to retain the
bookmarks
during Mail Merge. If so how??

Regards
Latha

.


.


.


.


  #12  
Old May 31st, 2004, 07:32 AM
Latha
external usenet poster
 
Posts: n/a
Default Bookmarks are not retained during Mail Merge

Doug,

I could see only 3 files with names Letter1.doc,
Letter2.doc and Letter3.doc. These documents seems to
contain bookmark text. A merged document by name Form
Letters... was created without bookmarks.

Also coming up with an error "Compile Error Expected: ="
at , in '), bmrange' macro
code 'System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames", "bookmark" & k),
bmrange
'. I did change the code to have := and ran the macro.

Regards
Latha

-----Original Message-----
The code worked here. When if finishes running, there

should be no # to be
seen as the final thing that it does is delete the #'s

that it inserts into
the mailmerge main document. Did you look in your

default document location
for a whole lot of files with the filename Letter#.doc?

They will be the
ones with the bookmarks in them.

--
Please post any further questions or followup to the

newsgroups for the
benefit of others who may be interested. Unsolicited

questions forwarded
directly to me will only be answered on a paid consulting

basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in

message
...
Thanks for the code Doug.

While running the macro from main document, message
saying "Word has insufficient memory. You will not be

able
to undo this action once it is completed. Do you want to
continue?" appeared twice. I hit Yes. All that's happend
was (1) '#' was inserted before and after the bookmark
range in the main document (2) bookmarks.txt created in

C
directory (3) merged document created without any
bookmarks (I couldn't see any # reference in there)

Your help much appreciated.

Regards
Latha


-----Original Message-----
If you run the following macro when the mailmerge main

document is active,
it will execute the merge to a new document, split that

new document into
individual documents with each document corresponding

to
a record in the
datasource and then it will recreate the bookmarks that

were in the main
document in each of those documents and save and close

them with a filename
"Letter#" where # is a sequential number:

' 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
Dim Target As Document, Letter As Range, source As

Document
Set source = ActiveDocument
i = 1
For Each abm In ActiveDocument.Range.Bookmarks
System.PrivateProfileString

("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name
abm.Range.InsertBefore "#"
abm.Range.InsertAfter "#"
i = i + 1
Next
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Set Result = ActiveDocument
For j = 1 To Result.Sections.Count - 1
Set Letter = Result.Sections(j).Range
Letter.End = Letter.End - 1
Set Target = Documents.Add
Target.Range = Letter
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
Target.Bookmarks.Add
System.PrivateProfileString

("c:\bookmarks.txt", "bookmarkNames", "bookmark"
& k), bmrange
k = k + 1
Loop
End With
Target.SaveAs FileName:="Letter" & j
Target.Close
Next j
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).Delete
bmrange.Characters(1).Delete
Loop
End With

If your mailmerge maindocument happens to include "#"

in
it, replace that
character wherever it appears in the above code with

some
other character
that does not appear in the document.
--
Please post any further questions or followup to the

newsgroups for the
benefit of others who may be interested. Unsolicited

questions forwarded
directly to me will only be answered on a paid

consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in

message
...
Doug

Let me try to explain bit more.

For example, I have a bookmark called bookmark1 which
takes to section 4.1 of the main document and another
bookmark I have was, say bookmark2 which takes to

section
1 highlighting the entire text under section 1; And

these
needs to be carried to the merged document.

Hope this helps.

Regards
Latha

-----Original Message-----
Sorry, that does not mean much. What is the

purpose of
the links?

--
Please post any further questions or followup to the
newsgroups for the
benefit of others who may be interested.

Unsolicited
questions forwarded
directly to me will only be answered on a paid

consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote

in
message
...
Sorry for not answering your question before,

Doug.
The
purpose of the bookmarks is to keep the links from

the
main document. Hope I am clear, if not please let

me
know.

Regards
Latha

-----Original Message-----
But what is the purpose of the bookmarks?

--
Please post any further questions or followup to

the
newsgroups for the
benefit of others who may be interested.

Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
wrote in

message
...
Thanks for your reply Doug. I wanted to carry

over
the
bookmarks from main document to the merged

document;
The
merged document should contain the same

bookmarks
from
the
main document. This main document is a template

and
any
merged document should resemble main document.

I am using Excel spreadsheet as data source and
performing
mail merge in Word 2000.

I tried macro code to replace bookmark field

with
placeholder in the main document, perform mail

merge
(close main document without saving any

changes),
then
in
the merged document replace placeholders with

the
bookmark; that worked but the problem is

placeholders
exists in the sense any attempts to delete
placeholder
is
deleting the bookmark.

Please advise. Many thanks in advance.

Regards
Latha

-----Original Message-----
As the name of each bookmark in a document

must
be
unique, they are not
retained when you create multiple copies in

the
document
as you do when you
execute a mailmerge.

Tell us what the purpose of the bookmarks is

and
we
may
be able to tell you
how to do whatever it is in another way.

--
Please post any further questions or followup

to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"

wrote
in
message
news:12ff401c4438a$a9085560

...
Hi

I wanted to know if its possible to retain

the
bookmarks
during Mail Merge. If so how??

Regards
Latha

.


.


.


.


.

  #13  
Old May 31st, 2004, 07:54 AM
Doug Robbins - Word MVP
external usenet poster
 
Posts: n/a
Default Bookmarks are not retained during Mail Merge

The following commands

System.PrivateProfileString("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name

and

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

should all be on one line. I assume that it is the second that is causing
the problem. Place the cursor after the second d in Add and press delete to
remove the line break inserted by the email program.

The multi-section document create by the mailmerge will not contain any
bookmarks. The macro splits that document into a separate document for each
record in the datasource and then uses and EditFind routine to insert
bookmarks in that document at the location of the # markers which it inserts
into the mailmerge main document. After creating each of those documents,
it saves and closes them. Then finally, it goes back to the mailmerge main
document and deletes the # markers that it inserted into it. At that point,
the mailmerge main document should be the active document. The multisection
document that was created as a result of the mailmerge will still be open
and in each Section of it, the location where the bookmarks inserted into
the mailmerge main document will be identified by the # markers. There will
however be no bookmarks in that document as in that it contains numerous
facsimiles of the mailmerge main document, it cannot contain the bookmarks
as they must be unique.
--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in message
...
Doug,

I could see only 3 files with names Letter1.doc,
Letter2.doc and Letter3.doc. These documents seems to
contain bookmark text. A merged document by name Form
Letters... was created without bookmarks.

Also coming up with an error "Compile Error Expected: ="
at , in '), bmrange' macro
code 'System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames", "bookmark" & k),
bmrange
'. I did change the code to have := and ran the macro.

Regards
Latha

-----Original Message-----
The code worked here. When if finishes running, there

should be no # to be
seen as the final thing that it does is delete the #'s

that it inserts into
the mailmerge main document. Did you look in your

default document location
for a whole lot of files with the filename Letter#.doc?

They will be the
ones with the bookmarks in them.

--
Please post any further questions or followup to the

newsgroups for the
benefit of others who may be interested. Unsolicited

questions forwarded
directly to me will only be answered on a paid consulting

basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in

message
...
Thanks for the code Doug.

While running the macro from main document, message
saying "Word has insufficient memory. You will not be

able
to undo this action once it is completed. Do you want to
continue?" appeared twice. I hit Yes. All that's happend
was (1) '#' was inserted before and after the bookmark
range in the main document (2) bookmarks.txt created in

C
directory (3) merged document created without any
bookmarks (I couldn't see any # reference in there)

Your help much appreciated.

Regards
Latha


-----Original Message-----
If you run the following macro when the mailmerge main
document is active,
it will execute the merge to a new document, split that
new document into
individual documents with each document corresponding

to
a record in the
datasource and then it will recreate the bookmarks that
were in the main
document in each of those documents and save and close
them with a filename
"Letter#" where # is a sequential number:

' 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
Dim Target As Document, Letter As Range, source As
Document
Set source = ActiveDocument
i = 1
For Each abm In ActiveDocument.Range.Bookmarks
System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name
abm.Range.InsertBefore "#"
abm.Range.InsertAfter "#"
i = i + 1
Next
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Set Result = ActiveDocument
For j = 1 To Result.Sections.Count - 1
Set Letter = Result.Sections(j).Range
Letter.End = Letter.End - 1
Set Target = Documents.Add
Target.Range = Letter
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
Target.Bookmarks.Add
System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames", "bookmark"
& k), bmrange
k = k + 1
Loop
End With
Target.SaveAs FileName:="Letter" & j
Target.Close
Next j
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).Delete
bmrange.Characters(1).Delete
Loop
End With

If your mailmerge maindocument happens to include "#"

in
it, replace that
character wherever it appears in the above code with

some
other character
that does not appear in the document.
--
Please post any further questions or followup to the
newsgroups for the
benefit of others who may be interested. Unsolicited
questions forwarded
directly to me will only be answered on a paid

consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in
message
...
Doug

Let me try to explain bit more.

For example, I have a bookmark called bookmark1 which
takes to section 4.1 of the main document and another
bookmark I have was, say bookmark2 which takes to
section
1 highlighting the entire text under section 1; And
these
needs to be carried to the merged document.

Hope this helps.

Regards
Latha

-----Original Message-----
Sorry, that does not mean much. What is the

purpose of
the links?

--
Please post any further questions or followup to the
newsgroups for the
benefit of others who may be interested.

Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote

in
message
...
Sorry for not answering your question before,

Doug.
The
purpose of the bookmarks is to keep the links from
the
main document. Hope I am clear, if not please let

me
know.

Regards
Latha

-----Original Message-----
But what is the purpose of the bookmarks?

--
Please post any further questions or followup to

the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
wrote in
message
...
Thanks for your reply Doug. I wanted to carry

over
the
bookmarks from main document to the merged
document;
The
merged document should contain the same

bookmarks
from
the
main document. This main document is a template
and
any
merged document should resemble main document.

I am using Excel spreadsheet as data source and
performing
mail merge in Word 2000.

I tried macro code to replace bookmark field

with
placeholder in the main document, perform mail
merge
(close main document without saving any

changes),
then
in
the merged document replace placeholders with

the
bookmark; that worked but the problem is
placeholders
exists in the sense any attempts to delete
placeholder
is
deleting the bookmark.

Please advise. Many thanks in advance.

Regards
Latha

-----Original Message-----
As the name of each bookmark in a document

must
be
unique, they are not
retained when you create multiple copies in

the
document
as you do when you
execute a mailmerge.

Tell us what the purpose of the bookmarks is

and
we
may
be able to tell you
how to do whatever it is in another way.

--
Please post any further questions or followup

to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"
wrote
in
message
news:12ff401c4438a$a9085560

...
Hi

I wanted to know if its possible to retain

the
bookmarks
during Mail Merge. If so how??

Regards
Latha

.


.


.


.


.


  #14  
Old June 4th, 2004, 05:19 AM
Latha
external usenet poster
 
Posts: n/a
Default Bookmarks are not retained during Mail Merge

Doug

My requirement is for the multi-section document created
by the mailmerge to retain the macros (not just the #s
where the bookmarks are inserted) contained in the main
document. Is it possible or not?? My understanding from
your mail is it is not possible. Is there a way to replace
#s with bookmark text??

Thanks in advance

Latha

-----Original Message-----
The following commands

System.PrivateProfileString

("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name

and

Target.Bookmarks.Add
System.PrivateProfileString

("c:\bookmarks.txt", "bookmarkNames", "bookmark"
& k), bmrange

should all be on one line. I assume that it is the

second that is causing
the problem. Place the cursor after the second d in Add

and press delete to
remove the line break inserted by the email program.

The multi-section document create by the mailmerge will

not contain any
bookmarks. The macro splits that document into a

separate document for each
record in the datasource and then uses and EditFind

routine to insert
bookmarks in that document at the location of the #

markers which it inserts
into the mailmerge main document. After creating each of

those documents,
it saves and closes them. Then finally, it goes back to

the mailmerge main
document and deletes the # markers that it inserted into

it. At that point,
the mailmerge main document should be the active

document. The multisection
document that was created as a result of the mailmerge

will still be open
and in each Section of it, the location where the

bookmarks inserted into
the mailmerge main document will be identified by the #

markers. There will
however be no bookmarks in that document as in that it

contains numerous
facsimiles of the mailmerge main document, it cannot

contain the bookmarks
as they must be unique.
--
Please post any further questions or followup to the

newsgroups for the
benefit of others who may be interested. Unsolicited

questions forwarded
directly to me will only be answered on a paid consulting

basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in

message
...
Doug,

I could see only 3 files with names Letter1.doc,
Letter2.doc and Letter3.doc. These documents seems to
contain bookmark text. A merged document by name Form
Letters... was created without bookmarks.

Also coming up with an error "Compile Error Expected: ="
at , in '), bmrange' macro
code 'System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames", "bookmark" & k),
bmrange
'. I did change the code to have := and ran the macro.

Regards
Latha

-----Original Message-----
The code worked here. When if finishes running, there

should be no # to be
seen as the final thing that it does is delete the #'s

that it inserts into
the mailmerge main document. Did you look in your

default document location
for a whole lot of files with the filename Letter#.doc?

They will be the
ones with the bookmarks in them.

--
Please post any further questions or followup to the

newsgroups for the
benefit of others who may be interested. Unsolicited

questions forwarded
directly to me will only be answered on a paid

consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in

message
...
Thanks for the code Doug.

While running the macro from main document, message
saying "Word has insufficient memory. You will not be

able
to undo this action once it is completed. Do you

want to
continue?" appeared twice. I hit Yes. All that's

happend
was (1) '#' was inserted before and after the

bookmark
range in the main document (2) bookmarks.txt created

in
C
directory (3) merged document created without any
bookmarks (I couldn't see any # reference in there)

Your help much appreciated.

Regards
Latha


-----Original Message-----
If you run the following macro when the mailmerge

main
document is active,
it will execute the merge to a new document, split

that
new document into
individual documents with each document

corresponding
to
a record in the
datasource and then it will recreate the bookmarks

that
were in the main
document in each of those documents and save and

close
them with a filename
"Letter#" where # is a sequential number:

' 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
Dim Target As Document, Letter As Range, source As
Document
Set source = ActiveDocument
i = 1
For Each abm In ActiveDocument.Range.Bookmarks
System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name
abm.Range.InsertBefore "#"
abm.Range.InsertAfter "#"
i = i + 1
Next
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Set Result = ActiveDocument
For j = 1 To Result.Sections.Count - 1
Set Letter = Result.Sections(j).Range
Letter.End = Letter.End - 1
Set Target = Documents.Add
Target.Range = Letter
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
Target.Bookmarks.Add
System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames", "bookmark"
& k), bmrange
k = k + 1
Loop
End With
Target.SaveAs FileName:="Letter" & j
Target.Close
Next j
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).Delete
bmrange.Characters(1).Delete
Loop
End With

If your mailmerge maindocument happens to

include "#"
in
it, replace that
character wherever it appears in the above code with

some
other character
that does not appear in the document.
--
Please post any further questions or followup to the
newsgroups for the
benefit of others who may be interested.

Unsolicited
questions forwarded
directly to me will only be answered on a paid

consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote

in
message
...
Doug

Let me try to explain bit more.

For example, I have a bookmark called bookmark1

which
takes to section 4.1 of the main document and

another
bookmark I have was, say bookmark2 which takes to
section
1 highlighting the entire text under section 1;

And
these
needs to be carried to the merged document.

Hope this helps.

Regards
Latha

-----Original Message-----
Sorry, that does not mean much. What is the

purpose of
the links?

--
Please post any further questions or followup to

the
newsgroups for the
benefit of others who may be interested.

Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"

wrote
in
message
...
Sorry for not answering your question before,

Doug.
The
purpose of the bookmarks is to keep the links

from
the
main document. Hope I am clear, if not please

let
me
know.

Regards
Latha

-----Original Message-----
But what is the purpose of the bookmarks?

--
Please post any further questions or followup

to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
wrote in
message
news:1320701c443b6$d0b8b010

...
Thanks for your reply Doug. I wanted to

carry
over
the
bookmarks from main document to the merged
document;
The
merged document should contain the same

bookmarks
from
the
main document. This main document is a

template
and
any
merged document should resemble main

document.

I am using Excel spreadsheet as data source

and
performing
mail merge in Word 2000.

I tried macro code to replace bookmark field

with
placeholder in the main document, perform

mail
merge
(close main document without saving any

changes),
then
in
the merged document replace placeholders

with
the
bookmark; that worked but the problem is
placeholders
exists in the sense any attempts to delete
placeholder
is
deleting the bookmark.

Please advise. Many thanks in advance.

Regards
Latha

-----Original Message-----
As the name of each bookmark in a document

must
be
unique, they are not
retained when you create multiple copies in

the
document
as you do when you
execute a mailmerge.

Tell us what the purpose of the bookmarks

is
and
we
may
be able to tell you
how to do whatever it is in another way.

--
Please post any further questions or

followup
to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a

paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"


wrote
in
message
news:12ff401c4438a$a9085560

...
Hi

I wanted to know if its possible to

retain
the
bookmarks
during Mail Merge. If so how??

Regards
Latha

.


.


.


.


.


.

  #15  
Old June 4th, 2004, 12:05 PM
Doug Robbins - Word MVP
external usenet poster
 
Posts: n/a
Default Bookmarks are not retained during Mail Merge

The macro that I gave you in my post of 31 May does insert bookmarks in each
document produced by the splitting the result of executing the mailmerge
that match the bookmarks that were in the mailmerge main document.

Now when you start talking about macros, that is something completely
different and leads me to believe that you are attempting to execute a
mailmerge with a main document that contains formfields as are used in a
document protected for formfields.

You may recall that I asked the purpose of the bookmarks and you never
really provided the answer to that.

Basically, a formfield document and the mailmerge utility are not
compatible. It may not however be correct to say that it is impossible to
re-create formfields and macros in the documents split out of the mailmerge,
but if you do, you are going to run into security issues if you start
distributing the documents and resulting problems when the recipients either
have their macro security level set to high, or choose not the trust (and
hence disable) the macros in the document when they receive the macro
security warning if they have the security level set to medium.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in message
...
Doug

My requirement is for the multi-section document created
by the mailmerge to retain the macros (not just the #s
where the bookmarks are inserted) contained in the main
document. Is it possible or not?? My understanding from
your mail is it is not possible. Is there a way to replace
#s with bookmark text??

Thanks in advance

Latha

-----Original Message-----
The following commands

System.PrivateProfileString

("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name

and

Target.Bookmarks.Add
System.PrivateProfileString

("c:\bookmarks.txt", "bookmarkNames", "bookmark"
& k), bmrange

should all be on one line. I assume that it is the

second that is causing
the problem. Place the cursor after the second d in Add

and press delete to
remove the line break inserted by the email program.

The multi-section document create by the mailmerge will

not contain any
bookmarks. The macro splits that document into a

separate document for each
record in the datasource and then uses and EditFind

routine to insert
bookmarks in that document at the location of the #

markers which it inserts
into the mailmerge main document. After creating each of

those documents,
it saves and closes them. Then finally, it goes back to

the mailmerge main
document and deletes the # markers that it inserted into

it. At that point,
the mailmerge main document should be the active

document. The multisection
document that was created as a result of the mailmerge

will still be open
and in each Section of it, the location where the

bookmarks inserted into
the mailmerge main document will be identified by the #

markers. There will
however be no bookmarks in that document as in that it

contains numerous
facsimiles of the mailmerge main document, it cannot

contain the bookmarks
as they must be unique.
--
Please post any further questions or followup to the

newsgroups for the
benefit of others who may be interested. Unsolicited

questions forwarded
directly to me will only be answered on a paid consulting

basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in

message
...
Doug,

I could see only 3 files with names Letter1.doc,
Letter2.doc and Letter3.doc. These documents seems to
contain bookmark text. A merged document by name Form
Letters... was created without bookmarks.

Also coming up with an error "Compile Error Expected: ="
at , in '), bmrange' macro
code 'System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames", "bookmark" & k),
bmrange
'. I did change the code to have := and ran the macro.

Regards
Latha

-----Original Message-----
The code worked here. When if finishes running, there
should be no # to be
seen as the final thing that it does is delete the #'s
that it inserts into
the mailmerge main document. Did you look in your
default document location
for a whole lot of files with the filename Letter#.doc?
They will be the
ones with the bookmarks in them.

--
Please post any further questions or followup to the
newsgroups for the
benefit of others who may be interested. Unsolicited
questions forwarded
directly to me will only be answered on a paid

consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in
message
...
Thanks for the code Doug.

While running the macro from main document, message
saying "Word has insufficient memory. You will not be
able
to undo this action once it is completed. Do you

want to
continue?" appeared twice. I hit Yes. All that's

happend
was (1) '#' was inserted before and after the

bookmark
range in the main document (2) bookmarks.txt created

in
C
directory (3) merged document created without any
bookmarks (I couldn't see any # reference in there)

Your help much appreciated.

Regards
Latha


-----Original Message-----
If you run the following macro when the mailmerge

main
document is active,
it will execute the merge to a new document, split

that
new document into
individual documents with each document

corresponding
to
a record in the
datasource and then it will recreate the bookmarks

that
were in the main
document in each of those documents and save and

close
them with a filename
"Letter#" where # is a sequential number:

' 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
Dim Target As Document, Letter As Range, source As
Document
Set source = ActiveDocument
i = 1
For Each abm In ActiveDocument.Range.Bookmarks
System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name
abm.Range.InsertBefore "#"
abm.Range.InsertAfter "#"
i = i + 1
Next
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Set Result = ActiveDocument
For j = 1 To Result.Sections.Count - 1
Set Letter = Result.Sections(j).Range
Letter.End = Letter.End - 1
Set Target = Documents.Add
Target.Range = Letter
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
Target.Bookmarks.Add
System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames", "bookmark"
& k), bmrange
k = k + 1
Loop
End With
Target.SaveAs FileName:="Letter" & j
Target.Close
Next j
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).Delete
bmrange.Characters(1).Delete
Loop
End With

If your mailmerge maindocument happens to

include "#"
in
it, replace that
character wherever it appears in the above code with
some
other character
that does not appear in the document.
--
Please post any further questions or followup to the
newsgroups for the
benefit of others who may be interested.

Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote

in
message
...
Doug

Let me try to explain bit more.

For example, I have a bookmark called bookmark1

which
takes to section 4.1 of the main document and

another
bookmark I have was, say bookmark2 which takes to
section
1 highlighting the entire text under section 1;

And
these
needs to be carried to the merged document.

Hope this helps.

Regards
Latha

-----Original Message-----
Sorry, that does not mean much. What is the
purpose of
the links?

--
Please post any further questions or followup to

the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"

wrote
in
message
...
Sorry for not answering your question before,
Doug.
The
purpose of the bookmarks is to keep the links

from
the
main document. Hope I am clear, if not please

let
me
know.

Regards
Latha

-----Original Message-----
But what is the purpose of the bookmarks?

--
Please post any further questions or followup

to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
wrote in
message
news:1320701c443b6$d0b8b010

...
Thanks for your reply Doug. I wanted to

carry
over
the
bookmarks from main document to the merged
document;
The
merged document should contain the same
bookmarks
from
the
main document. This main document is a

template
and
any
merged document should resemble main

document.

I am using Excel spreadsheet as data source

and
performing
mail merge in Word 2000.

I tried macro code to replace bookmark field
with
placeholder in the main document, perform

mail
merge
(close main document without saving any
changes),
then
in
the merged document replace placeholders

with
the
bookmark; that worked but the problem is
placeholders
exists in the sense any attempts to delete
placeholder
is
deleting the bookmark.

Please advise. Many thanks in advance.

Regards
Latha

-----Original Message-----
As the name of each bookmark in a document
must
be
unique, they are not
retained when you create multiple copies in
the
document
as you do when you
execute a mailmerge.

Tell us what the purpose of the bookmarks

is
and
we
may
be able to tell you
how to do whatever it is in another way.

--
Please post any further questions or

followup
to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a

paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"


wrote
in
message
news:12ff401c4438a$a9085560
...
Hi

I wanted to know if its possible to

retain
the
bookmarks
during Mail Merge. If so how??

Regards
Latha

.


.


.


.


.


.


  #16  
Old June 4th, 2004, 12:14 PM
Doug Robbins - Word MVP
external usenet poster
 
Posts: n/a
Default Bookmarks are not retained during Mail Merge

Also take a look at http://support.microsoft.com?kbid=211308

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in message
...
Doug

My requirement is for the multi-section document created
by the mailmerge to retain the macros (not just the #s
where the bookmarks are inserted) contained in the main
document. Is it possible or not?? My understanding from
your mail is it is not possible. Is there a way to replace
#s with bookmark text??

Thanks in advance

Latha

-----Original Message-----
The following commands

System.PrivateProfileString

("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name

and

Target.Bookmarks.Add
System.PrivateProfileString

("c:\bookmarks.txt", "bookmarkNames", "bookmark"
& k), bmrange

should all be on one line. I assume that it is the

second that is causing
the problem. Place the cursor after the second d in Add

and press delete to
remove the line break inserted by the email program.

The multi-section document create by the mailmerge will

not contain any
bookmarks. The macro splits that document into a

separate document for each
record in the datasource and then uses and EditFind

routine to insert
bookmarks in that document at the location of the #

markers which it inserts
into the mailmerge main document. After creating each of

those documents,
it saves and closes them. Then finally, it goes back to

the mailmerge main
document and deletes the # markers that it inserted into

it. At that point,
the mailmerge main document should be the active

document. The multisection
document that was created as a result of the mailmerge

will still be open
and in each Section of it, the location where the

bookmarks inserted into
the mailmerge main document will be identified by the #

markers. There will
however be no bookmarks in that document as in that it

contains numerous
facsimiles of the mailmerge main document, it cannot

contain the bookmarks
as they must be unique.
--
Please post any further questions or followup to the

newsgroups for the
benefit of others who may be interested. Unsolicited

questions forwarded
directly to me will only be answered on a paid consulting

basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in

message
...
Doug,

I could see only 3 files with names Letter1.doc,
Letter2.doc and Letter3.doc. These documents seems to
contain bookmark text. A merged document by name Form
Letters... was created without bookmarks.

Also coming up with an error "Compile Error Expected: ="
at , in '), bmrange' macro
code 'System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames", "bookmark" & k),
bmrange
'. I did change the code to have := and ran the macro.

Regards
Latha

-----Original Message-----
The code worked here. When if finishes running, there
should be no # to be
seen as the final thing that it does is delete the #'s
that it inserts into
the mailmerge main document. Did you look in your
default document location
for a whole lot of files with the filename Letter#.doc?
They will be the
ones with the bookmarks in them.

--
Please post any further questions or followup to the
newsgroups for the
benefit of others who may be interested. Unsolicited
questions forwarded
directly to me will only be answered on a paid

consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in
message
...
Thanks for the code Doug.

While running the macro from main document, message
saying "Word has insufficient memory. You will not be
able
to undo this action once it is completed. Do you

want to
continue?" appeared twice. I hit Yes. All that's

happend
was (1) '#' was inserted before and after the

bookmark
range in the main document (2) bookmarks.txt created

in
C
directory (3) merged document created without any
bookmarks (I couldn't see any # reference in there)

Your help much appreciated.

Regards
Latha


-----Original Message-----
If you run the following macro when the mailmerge

main
document is active,
it will execute the merge to a new document, split

that
new document into
individual documents with each document

corresponding
to
a record in the
datasource and then it will recreate the bookmarks

that
were in the main
document in each of those documents and save and

close
them with a filename
"Letter#" where # is a sequential number:

' 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
Dim Target As Document, Letter As Range, source As
Document
Set source = ActiveDocument
i = 1
For Each abm In ActiveDocument.Range.Bookmarks
System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name
abm.Range.InsertBefore "#"
abm.Range.InsertAfter "#"
i = i + 1
Next
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Set Result = ActiveDocument
For j = 1 To Result.Sections.Count - 1
Set Letter = Result.Sections(j).Range
Letter.End = Letter.End - 1
Set Target = Documents.Add
Target.Range = Letter
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
Target.Bookmarks.Add
System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames", "bookmark"
& k), bmrange
k = k + 1
Loop
End With
Target.SaveAs FileName:="Letter" & j
Target.Close
Next j
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).Delete
bmrange.Characters(1).Delete
Loop
End With

If your mailmerge maindocument happens to

include "#"
in
it, replace that
character wherever it appears in the above code with
some
other character
that does not appear in the document.
--
Please post any further questions or followup to the
newsgroups for the
benefit of others who may be interested.

Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote

in
message
...
Doug

Let me try to explain bit more.

For example, I have a bookmark called bookmark1

which
takes to section 4.1 of the main document and

another
bookmark I have was, say bookmark2 which takes to
section
1 highlighting the entire text under section 1;

And
these
needs to be carried to the merged document.

Hope this helps.

Regards
Latha

-----Original Message-----
Sorry, that does not mean much. What is the
purpose of
the links?

--
Please post any further questions or followup to

the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"

wrote
in
message
...
Sorry for not answering your question before,
Doug.
The
purpose of the bookmarks is to keep the links

from
the
main document. Hope I am clear, if not please

let
me
know.

Regards
Latha

-----Original Message-----
But what is the purpose of the bookmarks?

--
Please post any further questions or followup

to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
wrote in
message
news:1320701c443b6$d0b8b010

...
Thanks for your reply Doug. I wanted to

carry
over
the
bookmarks from main document to the merged
document;
The
merged document should contain the same
bookmarks
from
the
main document. This main document is a

template
and
any
merged document should resemble main

document.

I am using Excel spreadsheet as data source

and
performing
mail merge in Word 2000.

I tried macro code to replace bookmark field
with
placeholder in the main document, perform

mail
merge
(close main document without saving any
changes),
then
in
the merged document replace placeholders

with
the
bookmark; that worked but the problem is
placeholders
exists in the sense any attempts to delete
placeholder
is
deleting the bookmark.

Please advise. Many thanks in advance.

Regards
Latha

-----Original Message-----
As the name of each bookmark in a document
must
be
unique, they are not
retained when you create multiple copies in
the
document
as you do when you
execute a mailmerge.

Tell us what the purpose of the bookmarks

is
and
we
may
be able to tell you
how to do whatever it is in another way.

--
Please post any further questions or

followup
to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a

paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"


wrote
in
message
news:12ff401c4438a$a9085560
...
Hi

I wanted to know if its possible to

retain
the
bookmarks
during Mail Merge. If so how??

Regards
Latha

.


.


.


.


.


.


  #17  
Old June 7th, 2004, 02:15 AM
Latha
external usenet poster
 
Posts: n/a
Default Bookmarks are not retained during Mail Merge

Doug

I am very sorry for the confusion caused by me. My last
question posted should be "My requirement is for the multi-
section document created by the mailmerge to retain the
bookmarks (not just the #s where the bookmarks are
inserted) contained in the main document. Is it possible
or not??" I really confused you by saying 'macros' instead
of 'bookmarks'. the macro you posted is doing a great job
but what I need is, for the bookmarks to be in a multi-
section document not in separate documents. The documents
(Letter....doc) have only bookmarks in them but doesn't
look like a merged document.

I thought the answer provided on 30th May for the 'purpose
of the bookmarks' explains. Some of the bookmarks are like
an easy way of Search - Find. For example bookmark
Requirements takes to the Requirements section of the
document. Hope this explains.

Regards
Latha

-----Original Message-----
The macro that I gave you in my post of 31 May does

insert bookmarks in each
document produced by the splitting the result of

executing the mailmerge
that match the bookmarks that were in the mailmerge main

document.

Now when you start talking about macros, that is

something completely
different and leads me to believe that you are attempting

to execute a
mailmerge with a main document that contains formfields

as are used in a
document protected for formfields.

You may recall that I asked the purpose of the bookmarks

and you never
really provided the answer to that.

Basically, a formfield document and the mailmerge utility

are not
compatible. It may not however be correct to say that it

is impossible to
re-create formfields and macros in the documents split

out of the mailmerge,
but if you do, you are going to run into security issues

if you start
distributing the documents and resulting problems when

the recipients either
have their macro security level set to high, or choose

not the trust (and
hence disable) the macros in the document when they

receive the macro
security warning if they have the security level set to

medium.

--
Please post any further questions or followup to the

newsgroups for the
benefit of others who may be interested. Unsolicited

questions forwarded
directly to me will only be answered on a paid consulting

basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in

message
...
Doug

My requirement is for the multi-section document created
by the mailmerge to retain the macros (not just the #s
where the bookmarks are inserted) contained in the main
document. Is it possible or not?? My understanding from
your mail is it is not possible. Is there a way to

replace
#s with bookmark text??

Thanks in advance

Latha

-----Original Message-----
The following commands

System.PrivateProfileString

("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name

and

Target.Bookmarks.Add
System.PrivateProfileString

("c:\bookmarks.txt", "bookmarkNames", "bookmark"
& k), bmrange

should all be on one line. I assume that it is the

second that is causing
the problem. Place the cursor after the second d in

Add
and press delete to
remove the line break inserted by the email program.

The multi-section document create by the mailmerge will

not contain any
bookmarks. The macro splits that document into a

separate document for each
record in the datasource and then uses and EditFind

routine to insert
bookmarks in that document at the location of the #

markers which it inserts
into the mailmerge main document. After creating each

of
those documents,
it saves and closes them. Then finally, it goes back

to
the mailmerge main
document and deletes the # markers that it inserted

into
it. At that point,
the mailmerge main document should be the active

document. The multisection
document that was created as a result of the mailmerge

will still be open
and in each Section of it, the location where the

bookmarks inserted into
the mailmerge main document will be identified by the #

markers. There will
however be no bookmarks in that document as in that it

contains numerous
facsimiles of the mailmerge main document, it cannot

contain the bookmarks
as they must be unique.
--
Please post any further questions or followup to the

newsgroups for the
benefit of others who may be interested. Unsolicited

questions forwarded
directly to me will only be answered on a paid

consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in

message
...
Doug,

I could see only 3 files with names Letter1.doc,
Letter2.doc and Letter3.doc. These documents seems to
contain bookmark text. A merged document by name Form
Letters... was created without bookmarks.

Also coming up with an error "Compile Error

Expected: ="
at , in '), bmrange' macro
code 'System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames", "bookmark" &

k),
bmrange
'. I did change the code to have := and ran the

macro.

Regards
Latha

-----Original Message-----
The code worked here. When if finishes running,

there
should be no # to be
seen as the final thing that it does is delete the

#'s
that it inserts into
the mailmerge main document. Did you look in your
default document location
for a whole lot of files with the filename

Letter#.doc?
They will be the
ones with the bookmarks in them.

--
Please post any further questions or followup to the
newsgroups for the
benefit of others who may be interested.

Unsolicited
questions forwarded
directly to me will only be answered on a paid

consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote

in
message
...
Thanks for the code Doug.

While running the macro from main document,

message
saying "Word has insufficient memory. You will

not be
able
to undo this action once it is completed. Do you

want to
continue?" appeared twice. I hit Yes. All that's

happend
was (1) '#' was inserted before and after the

bookmark
range in the main document (2) bookmarks.txt

created
in
C
directory (3) merged document created without any
bookmarks (I couldn't see any # reference in

there)

Your help much appreciated.

Regards
Latha


-----Original Message-----
If you run the following macro when the mailmerge

main
document is active,
it will execute the merge to a new document,

split
that
new document into
individual documents with each document

corresponding
to
a record in the
datasource and then it will recreate the

bookmarks
that
were in the main
document in each of those documents and save and

close
them with a filename
"Letter#" where # is a sequential number:

' 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
Dim Target As Document, Letter As Range, source

As
Document
Set source = ActiveDocument
i = 1
For Each abm In ActiveDocument.Range.Bookmarks
System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name
abm.Range.InsertBefore "#"
abm.Range.InsertAfter "#"
i = i + 1
Next
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Set Result = ActiveDocument
For j = 1 To Result.Sections.Count - 1
Set Letter = Result.Sections(j).Range
Letter.End = Letter.End - 1
Set Target = Documents.Add
Target.Range = Letter
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
Target.Bookmarks.Add
System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames", "bookmark"
& k), bmrange
k = k + 1
Loop
End With
Target.SaveAs FileName:="Letter" & j
Target.Close
Next j
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).Delete
bmrange.Characters(1).Delete
Loop
End With

If your mailmerge maindocument happens to

include "#"
in
it, replace that
character wherever it appears in the above code

with
some
other character
that does not appear in the document.
--
Please post any further questions or followup to

the
newsgroups for the
benefit of others who may be interested.

Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"

wrote
in
message
...
Doug

Let me try to explain bit more.

For example, I have a bookmark called bookmark1

which
takes to section 4.1 of the main document and

another
bookmark I have was, say bookmark2 which takes

to
section
1 highlighting the entire text under section 1;

And
these
needs to be carried to the merged document.

Hope this helps.

Regards
Latha

-----Original Message-----
Sorry, that does not mean much. What is the
purpose of
the links?

--
Please post any further questions or followup

to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"

wrote
in
message
news:13db501c4443e$efdfa8d0

...
Sorry for not answering your question

before,
Doug.
The
purpose of the bookmarks is to keep the

links
from
the
main document. Hope I am clear, if not

please
let
me
know.

Regards
Latha

-----Original Message-----
But what is the purpose of the bookmarks?

--
Please post any further questions or

followup
to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a

paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP

wrote in
message
news:1320701c443b6$d0b8b010

...
Thanks for your reply Doug. I wanted to

carry
over
the
bookmarks from main document to the

merged
document;
The
merged document should contain the same
bookmarks
from
the
main document. This main document is a

template
and
any
merged document should resemble main

document.

I am using Excel spreadsheet as data

source
and
performing
mail merge in Word 2000.

I tried macro code to replace bookmark

field
with
placeholder in the main document, perform

mail
merge
(close main document without saving any
changes),
then
in
the merged document replace placeholders

with
the
bookmark; that worked but the problem is
placeholders
exists in the sense any attempts to

delete
placeholder
is
deleting the bookmark.

Please advise. Many thanks in advance.

Regards
Latha

-----Original Message-----
As the name of each bookmark in a

document
must
be
unique, they are not
retained when you create multiple

copies in
the
document
as you do when you
execute a mailmerge.

Tell us what the purpose of the

bookmarks
is
and
we
may
be able to tell you
how to do whatever it is in another way.

--
Please post any further questions or

followup
to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on

a
paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"


wrote
in
message
news:12ff401c4438a$a9085560
...
Hi

I wanted to know if its possible to

retain
the
bookmarks
during Mail Merge. If so how??

Regards
Latha

.


.


.


.


.


.


.

  #18  
Old June 7th, 2004, 04:17 AM
Doug Robbins - Word MVP
external usenet poster
 
Posts: n/a
Default Bookmarks are not retained during Mail Merge

As each bookmark in a document must have a unique name, it is not possible
to have bookmarks with the same name in each section of the multisection
document.

Why do you need the bookmarks??????????

If you will tell us the real reason for wanting them, we may be able to
suggest another method of achieving that objective.

IT CANNOT BE DONE WITH BOOKMARKS!!!!!!!!!!!!!!!!!
--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in message
...
Doug

I am very sorry for the confusion caused by me. My last
question posted should be "My requirement is for the multi-
section document created by the mailmerge to retain the
bookmarks (not just the #s where the bookmarks are
inserted) contained in the main document. Is it possible
or not??" I really confused you by saying 'macros' instead
of 'bookmarks'. the macro you posted is doing a great job
but what I need is, for the bookmarks to be in a multi-
section document not in separate documents. The documents
(Letter....doc) have only bookmarks in them but doesn't
look like a merged document.

I thought the answer provided on 30th May for the 'purpose
of the bookmarks' explains. Some of the bookmarks are like
an easy way of Search - Find. For example bookmark
Requirements takes to the Requirements section of the
document. Hope this explains.

Regards
Latha

-----Original Message-----
The macro that I gave you in my post of 31 May does

insert bookmarks in each
document produced by the splitting the result of

executing the mailmerge
that match the bookmarks that were in the mailmerge main

document.

Now when you start talking about macros, that is

something completely
different and leads me to believe that you are attempting

to execute a
mailmerge with a main document that contains formfields

as are used in a
document protected for formfields.

You may recall that I asked the purpose of the bookmarks

and you never
really provided the answer to that.

Basically, a formfield document and the mailmerge utility

are not
compatible. It may not however be correct to say that it

is impossible to
re-create formfields and macros in the documents split

out of the mailmerge,
but if you do, you are going to run into security issues

if you start
distributing the documents and resulting problems when

the recipients either
have their macro security level set to high, or choose

not the trust (and
hence disable) the macros in the document when they

receive the macro
security warning if they have the security level set to

medium.

--
Please post any further questions or followup to the

newsgroups for the
benefit of others who may be interested. Unsolicited

questions forwarded
directly to me will only be answered on a paid consulting

basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in

message
...
Doug

My requirement is for the multi-section document created
by the mailmerge to retain the macros (not just the #s
where the bookmarks are inserted) contained in the main
document. Is it possible or not?? My understanding from
your mail is it is not possible. Is there a way to

replace
#s with bookmark text??

Thanks in advance

Latha

-----Original Message-----
The following commands

System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name

and

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

should all be on one line. I assume that it is the
second that is causing
the problem. Place the cursor after the second d in

Add
and press delete to
remove the line break inserted by the email program.

The multi-section document create by the mailmerge will
not contain any
bookmarks. The macro splits that document into a
separate document for each
record in the datasource and then uses and EditFind
routine to insert
bookmarks in that document at the location of the #
markers which it inserts
into the mailmerge main document. After creating each

of
those documents,
it saves and closes them. Then finally, it goes back

to
the mailmerge main
document and deletes the # markers that it inserted

into
it. At that point,
the mailmerge main document should be the active
document. The multisection
document that was created as a result of the mailmerge
will still be open
and in each Section of it, the location where the
bookmarks inserted into
the mailmerge main document will be identified by the #
markers. There will
however be no bookmarks in that document as in that it
contains numerous
facsimiles of the mailmerge main document, it cannot
contain the bookmarks
as they must be unique.
--
Please post any further questions or followup to the
newsgroups for the
benefit of others who may be interested. Unsolicited
questions forwarded
directly to me will only be answered on a paid

consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in
message
...
Doug,

I could see only 3 files with names Letter1.doc,
Letter2.doc and Letter3.doc. These documents seems to
contain bookmark text. A merged document by name Form
Letters... was created without bookmarks.

Also coming up with an error "Compile Error

Expected: ="
at , in '), bmrange' macro
code 'System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames", "bookmark" &

k),
bmrange
'. I did change the code to have := and ran the

macro.

Regards
Latha

-----Original Message-----
The code worked here. When if finishes running,

there
should be no # to be
seen as the final thing that it does is delete the

#'s
that it inserts into
the mailmerge main document. Did you look in your
default document location
for a whole lot of files with the filename

Letter#.doc?
They will be the
ones with the bookmarks in them.

--
Please post any further questions or followup to the
newsgroups for the
benefit of others who may be interested.

Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote

in
message
...
Thanks for the code Doug.

While running the macro from main document,

message
saying "Word has insufficient memory. You will

not be
able
to undo this action once it is completed. Do you
want to
continue?" appeared twice. I hit Yes. All that's
happend
was (1) '#' was inserted before and after the
bookmark
range in the main document (2) bookmarks.txt

created
in
C
directory (3) merged document created without any
bookmarks (I couldn't see any # reference in

there)

Your help much appreciated.

Regards
Latha


-----Original Message-----
If you run the following macro when the mailmerge
main
document is active,
it will execute the merge to a new document,

split
that
new document into
individual documents with each document
corresponding
to
a record in the
datasource and then it will recreate the

bookmarks
that
were in the main
document in each of those documents and save and
close
them with a filename
"Letter#" where # is a sequential number:

' 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
Dim Target As Document, Letter As Range, source

As
Document
Set source = ActiveDocument
i = 1
For Each abm In ActiveDocument.Range.Bookmarks
System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name
abm.Range.InsertBefore "#"
abm.Range.InsertAfter "#"
i = i + 1
Next
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Set Result = ActiveDocument
For j = 1 To Result.Sections.Count - 1
Set Letter = Result.Sections(j).Range
Letter.End = Letter.End - 1
Set Target = Documents.Add
Target.Range = Letter
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
Target.Bookmarks.Add
System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames", "bookmark"
& k), bmrange
k = k + 1
Loop
End With
Target.SaveAs FileName:="Letter" & j
Target.Close
Next j
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).Delete
bmrange.Characters(1).Delete
Loop
End With

If your mailmerge maindocument happens to
include "#"
in
it, replace that
character wherever it appears in the above code

with
some
other character
that does not appear in the document.
--
Please post any further questions or followup to

the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"

wrote
in
message
...
Doug

Let me try to explain bit more.

For example, I have a bookmark called bookmark1
which
takes to section 4.1 of the main document and
another
bookmark I have was, say bookmark2 which takes

to
section
1 highlighting the entire text under section 1;
And
these
needs to be carried to the merged document.

Hope this helps.

Regards
Latha

-----Original Message-----
Sorry, that does not mean much. What is the
purpose of
the links?

--
Please post any further questions or followup

to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"
wrote
in
message
news:13db501c4443e$efdfa8d0

...
Sorry for not answering your question

before,
Doug.
The
purpose of the bookmarks is to keep the

links
from
the
main document. Hope I am clear, if not

please
let
me
know.

Regards
Latha

-----Original Message-----
But what is the purpose of the bookmarks?

--
Please post any further questions or

followup
to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a

paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP

wrote in
message
news:1320701c443b6$d0b8b010
...
Thanks for your reply Doug. I wanted to
carry
over
the
bookmarks from main document to the

merged
document;
The
merged document should contain the same
bookmarks
from
the
main document. This main document is a
template
and
any
merged document should resemble main
document.

I am using Excel spreadsheet as data

source
and
performing
mail merge in Word 2000.

I tried macro code to replace bookmark

field
with
placeholder in the main document, perform
mail
merge
(close main document without saving any
changes),
then
in
the merged document replace placeholders
with
the
bookmark; that worked but the problem is
placeholders
exists in the sense any attempts to

delete
placeholder
is
deleting the bookmark.

Please advise. Many thanks in advance.

Regards
Latha

-----Original Message-----
As the name of each bookmark in a

document
must
be
unique, they are not
retained when you create multiple

copies in
the
document
as you do when you
execute a mailmerge.

Tell us what the purpose of the

bookmarks
is
and
we
may
be able to tell you
how to do whatever it is in another way.

--
Please post any further questions or
followup
to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on

a
paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"

wrote
in
message
news:12ff401c4438a$a9085560
...
Hi

I wanted to know if its possible to
retain
the
bookmarks
during Mail Merge. If so how??

Regards
Latha

.


.


.


.


.


.


.


  #19  
Old June 7th, 2004, 07:26 AM
Latha
external usenet poster
 
Posts: n/a
Default Bookmarks are not retained during Mail Merge

Doug, thank you very much for your patience.

Below is the explanation about the purpose of the
bookmarks from the actual person who created the main
document (tempalte)

This Word document is in reality a template that is used
each time to create a final version. The hyperlinks placed
within the document were designed to provide easy
navigation back and forth throughout the document. For
instance a hyperlink within a clause on page 3 might refer
to another clause within the document on page 17. The
reader could simply click on the link and be taken to the
correct area on page 17. Then using another link within
the clause on page 17 they would be taken back to page 3.
Then they could continue to read the document from page 3.

It has become obvious that 'manually created' hyperlinks
link to specific bookmarks. But these bookmarks do not
survive the standard mail merge process. However the
actual hyperlink field code does survive intact. The
problem is that it now points to a non-existent
reference.

However we have discovered that a macro command to create
a table of contents does survive the mail merge. When it
is activated it creates the table of contents and
hyperlinks linked to hidden bookmarks i.e. Toc 74385131.
These newly created 'hidden bookmarks' point to any text
with a heading style.

So it might be possible to change the existing hyperlinks
to refer to bookmarks that will only exist once the 'table
of contents' macro is activated after the mail merge.

Hope this explains better.

Regards and thanks in advance
Latha


-----Original Message-----
As each bookmark in a document must have a unique name,

it is not possible
to have bookmarks with the same name in each section of

the multisection
document.

Why do you need the bookmarks??????????

If you will tell us the real reason for wanting them, we

may be able to
suggest another method of achieving that objective.

IT CANNOT BE DONE WITH BOOKMARKS!!!!!!!!!!!!!!!!!
--
Please post any further questions or followup to the

newsgroups for the
benefit of others who may be interested. Unsolicited

questions forwarded
directly to me will only be answered on a paid consulting

basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in

message
...
Doug

I am very sorry for the confusion caused by me. My last
question posted should be "My requirement is for the

multi-
section document created by the mailmerge to retain the
bookmarks (not just the #s where the bookmarks are
inserted) contained in the main document. Is it possible
or not??" I really confused you by saying 'macros'

instead
of 'bookmarks'. the macro you posted is doing a great

job
but what I need is, for the bookmarks to be in a multi-
section document not in separate documents. The

documents
(Letter....doc) have only bookmarks in them but doesn't
look like a merged document.

I thought the answer provided on 30th May for

the 'purpose
of the bookmarks' explains. Some of the bookmarks are

like
an easy way of Search - Find. For example bookmark
Requirements takes to the Requirements section of the
document. Hope this explains.

Regards
Latha

-----Original Message-----
The macro that I gave you in my post of 31 May does

insert bookmarks in each
document produced by the splitting the result of

executing the mailmerge
that match the bookmarks that were in the mailmerge

main
document.

Now when you start talking about macros, that is

something completely
different and leads me to believe that you are

attempting
to execute a
mailmerge with a main document that contains formfields

as are used in a
document protected for formfields.

You may recall that I asked the purpose of the

bookmarks
and you never
really provided the answer to that.

Basically, a formfield document and the mailmerge

utility
are not
compatible. It may not however be correct to say that

it
is impossible to
re-create formfields and macros in the documents split

out of the mailmerge,
but if you do, you are going to run into security

issues
if you start
distributing the documents and resulting problems when

the recipients either
have their macro security level set to high, or choose

not the trust (and
hence disable) the macros in the document when they

receive the macro
security warning if they have the security level set to

medium.

--
Please post any further questions or followup to the

newsgroups for the
benefit of others who may be interested. Unsolicited

questions forwarded
directly to me will only be answered on a paid

consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in

message
...
Doug

My requirement is for the multi-section document

created
by the mailmerge to retain the macros (not just the

#s
where the bookmarks are inserted) contained in the

main
document. Is it possible or not?? My understanding

from
your mail is it is not possible. Is there a way to

replace
#s with bookmark text??

Thanks in advance

Latha

-----Original Message-----
The following commands

System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name

and

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

should all be on one line. I assume that it is the
second that is causing
the problem. Place the cursor after the second d in

Add
and press delete to
remove the line break inserted by the email program.

The multi-section document create by the mailmerge

will
not contain any
bookmarks. The macro splits that document into a
separate document for each
record in the datasource and then uses and EditFind
routine to insert
bookmarks in that document at the location of the #
markers which it inserts
into the mailmerge main document. After creating

each
of
those documents,
it saves and closes them. Then finally, it goes

back
to
the mailmerge main
document and deletes the # markers that it inserted

into
it. At that point,
the mailmerge main document should be the active
document. The multisection
document that was created as a result of the

mailmerge
will still be open
and in each Section of it, the location where the
bookmarks inserted into
the mailmerge main document will be identified by

the #
markers. There will
however be no bookmarks in that document as in that

it
contains numerous
facsimiles of the mailmerge main document, it cannot
contain the bookmarks
as they must be unique.
--
Please post any further questions or followup to the
newsgroups for the
benefit of others who may be interested.

Unsolicited
questions forwarded
directly to me will only be answered on a paid

consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote

in
message
...
Doug,

I could see only 3 files with names Letter1.doc,
Letter2.doc and Letter3.doc. These documents

seems to
contain bookmark text. A merged document by name

Form
Letters... was created without bookmarks.

Also coming up with an error "Compile Error

Expected: ="
at , in '), bmrange' macro
code 'System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames", "bookmark" &

k),
bmrange
'. I did change the code to have := and ran the

macro.

Regards
Latha

-----Original Message-----
The code worked here. When if finishes running,

there
should be no # to be
seen as the final thing that it does is delete

the
#'s
that it inserts into
the mailmerge main document. Did you look in

your
default document location
for a whole lot of files with the filename

Letter#.doc?
They will be the
ones with the bookmarks in them.

--
Please post any further questions or followup to

the
newsgroups for the
benefit of others who may be interested.

Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"

wrote
in
message
...
Thanks for the code Doug.

While running the macro from main document,

message
saying "Word has insufficient memory. You will

not be
able
to undo this action once it is completed. Do

you
want to
continue?" appeared twice. I hit Yes. All

that's
happend
was (1) '#' was inserted before and after the
bookmark
range in the main document (2) bookmarks.txt

created
in
C
directory (3) merged document created without

any
bookmarks (I couldn't see any # reference in

there)

Your help much appreciated.

Regards
Latha


-----Original Message-----
If you run the following macro when the

mailmerge
main
document is active,
it will execute the merge to a new document,

split
that
new document into
individual documents with each document
corresponding
to
a record in the
datasource and then it will recreate the

bookmarks
that
were in the main
document in each of those documents and save

and
close
them with a filename
"Letter#" where # is a sequential number:

' 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
Dim Target As Document, Letter As Range,

source
As
Document
Set source = ActiveDocument
i = 1
For Each abm In ActiveDocument.Range.Bookmarks
System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name
abm.Range.InsertBefore "#"
abm.Range.InsertAfter "#"
i = i + 1
Next
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Set Result = ActiveDocument
For j = 1 To Result.Sections.Count - 1
Set Letter = Result.Sections(j).Range
Letter.End = Letter.End - 1
Set Target = Documents.Add
Target.Range = Letter
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
Target.Bookmarks.Add
System.PrivateProfileString

("c:\bookmarks.txt", "bookmarkNames", "bookmark"
& k), bmrange
k = k + 1
Loop
End With
Target.SaveAs FileName:="Letter" & j
Target.Close
Next j
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).Delete
bmrange.Characters(1).Delete
Loop
End With

If your mailmerge maindocument happens to
include "#"
in
it, replace that
character wherever it appears in the above

code
with
some
other character
that does not appear in the document.
--
Please post any further questions or followup

to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"

wrote
in
message
...
Doug

Let me try to explain bit more.

For example, I have a bookmark called

bookmark1
which
takes to section 4.1 of the main document

and
another
bookmark I have was, say bookmark2 which

takes
to
section
1 highlighting the entire text under

section 1;
And
these
needs to be carried to the merged document.

Hope this helps.

Regards
Latha

-----Original Message-----
Sorry, that does not mean much. What is

the
purpose of
the links?

--
Please post any further questions or

followup
to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a

paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"


wrote
in
message
news:13db501c4443e$efdfa8d0

...
Sorry for not answering your question

before,
Doug.
The
purpose of the bookmarks is to keep the

links
from
the
main document. Hope I am clear, if not

please
let
me
know.

Regards
Latha

-----Original Message-----
But what is the purpose of the

bookmarks?

--
Please post any further questions or

followup
to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on

a
paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP

wrote in
message
news:1320701c443b6$d0b8b010
...
Thanks for your reply Doug. I wanted

to
carry
over
the
bookmarks from main document to the

merged
document;
The
merged document should contain the

same
bookmarks
from
the
main document. This main document is a
template
and
any
merged document should resemble main
document.

I am using Excel spreadsheet as data

source
and
performing
mail merge in Word 2000.

I tried macro code to replace bookmark

field
with
placeholder in the main document,

perform
mail
merge
(close main document without saving

any
changes),
then
in
the merged document replace

placeholders
with
the
bookmark; that worked but the problem

is
placeholders
exists in the sense any attempts to

delete
placeholder
is
deleting the bookmark.

Please advise. Many thanks in advance.

Regards
Latha

-----Original Message-----
As the name of each bookmark in a

document
must
be
unique, they are not
retained when you create multiple

copies in
the
document
as you do when you
execute a mailmerge.

Tell us what the purpose of the

bookmarks
is
and
we
may
be able to tell you
how to do whatever it is in another

way.

--
Please post any further questions or
followup
to
the
newsgroups for the
benefit of others who may be

interested.
Unsolicited
questions forwarded
directly to me will only be answered

on
a
paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"

wrote
in
message
news:12ff401c4438a$a9085560
...
Hi

I wanted to know if its possible to
retain
the
bookmarks
during Mail Merge. If so how??

Regards
Latha

.


.


.


.


.


.


.


.

  #20  
Old June 7th, 2004, 03:13 PM
Doug Robbins - Word MVP
external usenet poster
 
Posts: n/a
Default Bookmarks are not retained during Mail Merge

The following might do what you want:

' Throwaway Macro created by Doug Robbins to "preserve" hyperlinks to
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


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in message
...
Doug, thank you very much for your patience.

Below is the explanation about the purpose of the
bookmarks from the actual person who created the main
document (tempalte)

This Word document is in reality a template that is used
each time to create a final version. The hyperlinks placed
within the document were designed to provide easy
navigation back and forth throughout the document. For
instance a hyperlink within a clause on page 3 might refer
to another clause within the document on page 17. The
reader could simply click on the link and be taken to the
correct area on page 17. Then using another link within
the clause on page 17 they would be taken back to page 3.
Then they could continue to read the document from page 3.

It has become obvious that 'manually created' hyperlinks
link to specific bookmarks. But these bookmarks do not
survive the standard mail merge process. However the
actual hyperlink field code does survive intact. The
problem is that it now points to a non-existent
reference.

However we have discovered that a macro command to create
a table of contents does survive the mail merge. When it
is activated it creates the table of contents and
hyperlinks linked to hidden bookmarks i.e. Toc 74385131.
These newly created 'hidden bookmarks' point to any text
with a heading style.

So it might be possible to change the existing hyperlinks
to refer to bookmarks that will only exist once the 'table
of contents' macro is activated after the mail merge.

Hope this explains better.

Regards and thanks in advance
Latha


-----Original Message-----
As each bookmark in a document must have a unique name,

it is not possible
to have bookmarks with the same name in each section of

the multisection
document.

Why do you need the bookmarks??????????

If you will tell us the real reason for wanting them, we

may be able to
suggest another method of achieving that objective.

IT CANNOT BE DONE WITH BOOKMARKS!!!!!!!!!!!!!!!!!
--
Please post any further questions or followup to the

newsgroups for the
benefit of others who may be interested. Unsolicited

questions forwarded
directly to me will only be answered on a paid consulting

basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in

message
...
Doug

I am very sorry for the confusion caused by me. My last
question posted should be "My requirement is for the

multi-
section document created by the mailmerge to retain the
bookmarks (not just the #s where the bookmarks are
inserted) contained in the main document. Is it possible
or not??" I really confused you by saying 'macros'

instead
of 'bookmarks'. the macro you posted is doing a great

job
but what I need is, for the bookmarks to be in a multi-
section document not in separate documents. The

documents
(Letter....doc) have only bookmarks in them but doesn't
look like a merged document.

I thought the answer provided on 30th May for

the 'purpose
of the bookmarks' explains. Some of the bookmarks are

like
an easy way of Search - Find. For example bookmark
Requirements takes to the Requirements section of the
document. Hope this explains.

Regards
Latha

-----Original Message-----
The macro that I gave you in my post of 31 May does
insert bookmarks in each
document produced by the splitting the result of
executing the mailmerge
that match the bookmarks that were in the mailmerge

main
document.

Now when you start talking about macros, that is
something completely
different and leads me to believe that you are

attempting
to execute a
mailmerge with a main document that contains formfields
as are used in a
document protected for formfields.

You may recall that I asked the purpose of the

bookmarks
and you never
really provided the answer to that.

Basically, a formfield document and the mailmerge

utility
are not
compatible. It may not however be correct to say that

it
is impossible to
re-create formfields and macros in the documents split
out of the mailmerge,
but if you do, you are going to run into security

issues
if you start
distributing the documents and resulting problems when
the recipients either
have their macro security level set to high, or choose
not the trust (and
hence disable) the macros in the document when they
receive the macro
security warning if they have the security level set to
medium.

--
Please post any further questions or followup to the
newsgroups for the
benefit of others who may be interested. Unsolicited
questions forwarded
directly to me will only be answered on a paid

consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote in
message
...
Doug

My requirement is for the multi-section document

created
by the mailmerge to retain the macros (not just the

#s
where the bookmarks are inserted) contained in the

main
document. Is it possible or not?? My understanding

from
your mail is it is not possible. Is there a way to
replace
#s with bookmark text??

Thanks in advance

Latha

-----Original Message-----
The following commands

System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name

and

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

should all be on one line. I assume that it is the
second that is causing
the problem. Place the cursor after the second d in
Add
and press delete to
remove the line break inserted by the email program.

The multi-section document create by the mailmerge

will
not contain any
bookmarks. The macro splits that document into a
separate document for each
record in the datasource and then uses and EditFind
routine to insert
bookmarks in that document at the location of the #
markers which it inserts
into the mailmerge main document. After creating

each
of
those documents,
it saves and closes them. Then finally, it goes

back
to
the mailmerge main
document and deletes the # markers that it inserted
into
it. At that point,
the mailmerge main document should be the active
document. The multisection
document that was created as a result of the

mailmerge
will still be open
and in each Section of it, the location where the
bookmarks inserted into
the mailmerge main document will be identified by

the #
markers. There will
however be no bookmarks in that document as in that

it
contains numerous
facsimiles of the mailmerge main document, it cannot
contain the bookmarks
as they must be unique.
--
Please post any further questions or followup to the
newsgroups for the
benefit of others who may be interested.

Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha" wrote

in
message
...
Doug,

I could see only 3 files with names Letter1.doc,
Letter2.doc and Letter3.doc. These documents

seems to
contain bookmark text. A merged document by name

Form
Letters... was created without bookmarks.

Also coming up with an error "Compile Error
Expected: ="
at , in '), bmrange' macro
code 'System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames", "bookmark" &
k),
bmrange
'. I did change the code to have := and ran the
macro.

Regards
Latha

-----Original Message-----
The code worked here. When if finishes running,
there
should be no # to be
seen as the final thing that it does is delete

the
#'s
that it inserts into
the mailmerge main document. Did you look in

your
default document location
for a whole lot of files with the filename
Letter#.doc?
They will be the
ones with the bookmarks in them.

--
Please post any further questions or followup to

the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"

wrote
in
message
...
Thanks for the code Doug.

While running the macro from main document,
message
saying "Word has insufficient memory. You will
not be
able
to undo this action once it is completed. Do

you
want to
continue?" appeared twice. I hit Yes. All

that's
happend
was (1) '#' was inserted before and after the
bookmark
range in the main document (2) bookmarks.txt
created
in
C
directory (3) merged document created without

any
bookmarks (I couldn't see any # reference in
there)

Your help much appreciated.

Regards
Latha


-----Original Message-----
If you run the following macro when the

mailmerge
main
document is active,
it will execute the merge to a new document,
split
that
new document into
individual documents with each document
corresponding
to
a record in the
datasource and then it will recreate the
bookmarks
that
were in the main
document in each of those documents and save

and
close
them with a filename
"Letter#" where # is a sequential number:

' 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
Dim Target As Document, Letter As Range,

source
As
Document
Set source = ActiveDocument
i = 1
For Each abm In ActiveDocument.Range.Bookmarks
System.PrivateProfileString
("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name
abm.Range.InsertBefore "#"
abm.Range.InsertAfter "#"
i = i + 1
Next
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Set Result = ActiveDocument
For j = 1 To Result.Sections.Count - 1
Set Letter = Result.Sections(j).Range
Letter.End = Letter.End - 1
Set Target = Documents.Add
Target.Range = Letter
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
Target.Bookmarks.Add
System.PrivateProfileString

("c:\bookmarks.txt", "bookmarkNames", "bookmark"
& k), bmrange
k = k + 1
Loop
End With
Target.SaveAs FileName:="Letter" & j
Target.Close
Next j
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).Delete
bmrange.Characters(1).Delete
Loop
End With

If your mailmerge maindocument happens to
include "#"
in
it, replace that
character wherever it appears in the above

code
with
some
other character
that does not appear in the document.
--
Please post any further questions or followup

to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"
wrote
in
message
...
Doug

Let me try to explain bit more.

For example, I have a bookmark called

bookmark1
which
takes to section 4.1 of the main document

and
another
bookmark I have was, say bookmark2 which

takes
to
section
1 highlighting the entire text under

section 1;
And
these
needs to be carried to the merged document.

Hope this helps.

Regards
Latha

-----Original Message-----
Sorry, that does not mean much. What is

the
purpose of
the links?

--
Please post any further questions or

followup
to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on a

paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"


wrote
in
message
news:13db501c4443e$efdfa8d0
...
Sorry for not answering your question
before,
Doug.
The
purpose of the bookmarks is to keep the
links
from
the
main document. Hope I am clear, if not
please
let
me
know.

Regards
Latha

-----Original Message-----
But what is the purpose of the

bookmarks?

--
Please post any further questions or
followup
to
the
newsgroups for the
benefit of others who may be interested.
Unsolicited
questions forwarded
directly to me will only be answered on

a
paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP

wrote in
message
news:1320701c443b6$d0b8b010
...
Thanks for your reply Doug. I wanted

to
carry
over
the
bookmarks from main document to the
merged
document;
The
merged document should contain the

same
bookmarks
from
the
main document. This main document is a
template
and
any
merged document should resemble main
document.

I am using Excel spreadsheet as data
source
and
performing
mail merge in Word 2000.

I tried macro code to replace bookmark
field
with
placeholder in the main document,

perform
mail
merge
(close main document without saving

any
changes),
then
in
the merged document replace

placeholders
with
the
bookmark; that worked but the problem

is
placeholders
exists in the sense any attempts to
delete
placeholder
is
deleting the bookmark.

Please advise. Many thanks in advance.

Regards
Latha

-----Original Message-----
As the name of each bookmark in a
document
must
be
unique, they are not
retained when you create multiple
copies in
the
document
as you do when you
execute a mailmerge.

Tell us what the purpose of the
bookmarks
is
and
we
may
be able to tell you
how to do whatever it is in another

way.

--
Please post any further questions or
followup
to
the
newsgroups for the
benefit of others who may be

interested.
Unsolicited
questions forwarded
directly to me will only be answered

on
a
paid
consulting
basis.

Hope this helps
Doug Robbins - Word MVP
"Latha"

wrote
in
message
news:12ff401c4438a$a9085560
...
Hi

I wanted to know if its possible to
retain
the
bookmarks
during Mail Merge. If so how??

Regards
Latha

.


.


.


.


.


.


.


.


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


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


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.