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
> Hi Marty,
>
[quoted text clipped - 11 lines]
> Word XP, Win 98
> http://word.mvps.org/
Charles Kenyon - 03 Feb 2005 15:33 GMT
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.

Signature
Charles Kenyon
Word New User FAQ & Web Directory: http://addbalance.com/word
Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide
See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
> Hi Helmut-
>
[quoted text clipped - 43 lines]
>> Word XP, Win 98
>> http://word.mvps.org/
Helmut Weber - 04 Feb 2005 21:06 GMT
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/
Marty - 08 Feb 2005 15:59 GMT
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
> Hi Marty,
>
[quoted text clipped - 14 lines]
> Word XP, Win 98
> http://word.mvps.org/
Helmut Weber - 15 Feb 2005 12:55 GMT
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/