Bookmarks in a template

M

Marty

Hi-

I have a Word97 template with 3 bookmarks. After I run a macro which does a
MailMerge, the resulting document does not have the bookmarks.

Why? All other text from the template is in the new document.

How can the bookmarks also be "carried forth" into the created document?

(I created the bookmarks by positioning the cursor where I wanted, and going
to the Insert Tab, and then selecting Bookmark. I entered the bookmark name,
and hit the Add button.)

Thanks,

Marty
 
H

Helmut Weber

Hi Marty,

no way! A bookmark is a unique location.
So, it is not possible to have the same bookmark
more than once in a document.
Workarounds? Probably.
Possibly pretty complicated.
If you could tell us, what exactly you want to do.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
M

Marty

Hi Helmut-

I am generating a document using a Word97 template (.dot). As the user
checks off checkboxes and optionboxes, I will know if parts of the template
should be eliminated.

So, I thought that if I put in some bookmarks into the template, I could
then add to the macro a section that would delete the text between the
certain bookmarks if it is not required.

But the bookmarks do not appear in the merged document.

For example: If I have a 4 pages of text in the middle of the template
referring to stamp collecting, but the user checks the box that says he is
not a stamp collector, then I do not want to show those 4 pages after the
mailmerge.

I thought that by putting a bookmark (BK1) before these 4 pages, and another
bookmark (BK2) after, that I could then delete all text between these 2
bookmarks just after the code that does the mailmerge. But the bookmarks do
not appear in the merged document.

So, how may I delete the 4 pages? (I have several of these sections which
may or may not be deleted, depending on the answers to the check boxes.)

Thanks,

Marty
 
C

Charles Kenyon

If you use mailmerge to a new result document, all bookmarks (and fields)
are lost. See if you can generate your result without a final mailmerge. I
use mailmerge with single records and use the merge preview screen. This
still has fields and bookmarks.
 
H

Helmut Weber

Hi Marty,

sometimes the most simple way is the best.
Instead of using bookmarks, it may be possible
to use unique strings like #0# and #1# instead
of bookmarks. Delete them and all in between in
case 1 or just the strings themselves in case 2.

If that would destroy your formatting, it may be
possible to use colors, or some otherwise
not used formatting.


Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
M

Marty

Hi Helmut-

Yes, I see your point. So, I created a test macro:

Sub test()
Dim oRng As Range
'
'
With ActiveDocument
Set oRng = .Range _
(Start:=.Text("#000#").Range.End, _
End:=.text("#111#").Range.Start)
oRng.Delete
End With


End Sub


But it gives me a Run-time error 438 (Object doesn't support this property
or method.)

Is there other coding that can be used? (Remember, I'm running Word97.)

Thanks for all your time and help.

-Marty
 
H

Helmut Weber

Hi Marty,

somehow this thread got lost.


Sub Makro11()
Dim rDcm As Range
Dim rTmp As Range
Set rDcm = ActiveDocument.Range
Set rTmp = Selection.Range
ResetSearch
With rDcm.Find
.Text = "#001#"
If .Execute Then
rTmp.Start = rDcm.Start
rDcm.Collapse direction:=wdCollapseEnd
.Text = "#002#"
If .Execute Then
rTmp.End = rDcm.End
rTmp.Select
' or delete it
End If
End If
End With
ResetSearch
End Sub

Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
' plus some more
.Execute
End With
End Sub

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top