Hello all. I am trying to format a log file from ACL that is inserted into
Word. There is certain code when commented that we do not want to show up in
the Word document. I cannot seem to write a successful loop to do the
following:
1) Search for the phrase "COMMENT - Begin Delete" in the word document
2) Delete that phrase and any subsequent characters until it finds the next
phrase "COMMENT - End Delete" (inwhich that phrase also needs to be deleted)
My idea was to do something similar to below but I need it to be able to
delete the range multiple times if it appears.
Selection.Find.ClearFormatting
With Selection.Find
.Text = "COMMENT - Begin Delete"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Extend
Selection.ClearFormatting
With Selection.Find
.Text = "COMMENT - End Delete"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Delete
Selection.HomeKey Unit:=wdStory
Thanks for any help you may be able to provide!
-Brad
You don't really need a macro to do it. Use Edit>Replace and click on the
More button and then check the "Use Wildcards" box and enter
COMMENT - Begin Delete * COMMENT - End Delete
into the Find what control and leave the Replace with control empty and then
click on Replace All.

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
> Hello all. I am trying to format a log file from ACL that is inserted
> into
[quoted text clipped - 46 lines]
> Thanks for any help you may be able to provide!
> -Brad
Brad - 22 Nov 2005 20:22 GMT
Doug, thanks for the response. However, I will need to create a macro for
this. We run a macro that kicks off about 30 macros in turn to format our
log files a certain way in MS Word. This is another feature that has been
requested of me to add.
Thanks!
Brad
> You don't really need a macro to do it. Use Edit>Replace and click on the
> More button and then check the "Use Wildcards" box and enter
[quoted text clipped - 54 lines]
> > Thanks for any help you may be able to provide!
> > -Brad
Brad - 22 Nov 2005 22:20 GMT
I tried out the wildcard search and it worked, but only if the 2 phrases were
on the same line. I should have mentioned that these phrases will occur
around blocks of code that we want deleted.
Any further help would be appreciated developing this macro!
-Brad
> You don't really need a macro to do it. Use Edit>Replace and click on the
> More button and then check the "Use Wildcards" box and enter
[quoted text clipped - 54 lines]
> > Thanks for any help you may be able to provide!
> > -Brad