Does .Delete work in Word2003 11.5604.5606

M

Marty

Hi-

I have some VBA code:


If LPPCI0.AddedPages.Value <> True Then
With Selection
.HomeKey Unit:=wdStory
.Find.Execute FindText:="[transmittal]"
.ExtendMode = True
.Find.Execute FindText:="[added pages]"
.Delete
End With
End If

If LPPCI3.OptionButton17 <> True Then
With Selection
.HomeKey Unit:=wdStory
.Find.Execute FindText:="[added pages]"
.ExtendMode = True
.Find.Execute FindText:="[cover sheet]"
.Delete
End With
End If

When I step through, I can see the cursor going to each and every line. Both
LPPCI0.AddedPages and LPPCI3.OptionButton17 are false. But it does not seem
to be deleting the portions of the document between [transmittal] & [added
pages] and between [added pages] & [cover sheet]. Why???? Does .Delete not
work?

[transmittal], [added pages] & [cover sheet] are all in the .dot template.
The verbiage is not being deleted after the mailmerge.

It's driving me nuts.

Please help.

Thanks.
 
C

Cindy M.

Hi =?Utf-8?B?TWFydHk=?=,

When you step into and beyond a find.execute line, does the selection actually
change to select, for example, [transmittal]?

You aren't specifying most of the Find properties and methods (ClearFormatting
being important, among others). When you use the Selection object with Find,
any and everything set in the Find dialog will be applied. Such as MatchCase or
MatchWildcards. Possibly something in the dialog box is making it so things
aren't found?
I have some VBA code:


If LPPCI0.AddedPages.Value <> True Then
With Selection
.HomeKey Unit:=wdStory
.Find.Execute FindText:="[transmittal]"
.ExtendMode = True
.Find.Execute FindText:="[added pages]"
.Delete
End With
End If

If LPPCI3.OptionButton17 <> True Then
With Selection
.HomeKey Unit:=wdStory
.Find.Execute FindText:="[added pages]"
.ExtendMode = True
.Find.Execute FindText:="[cover sheet]"
.Delete
End With
End If

When I step through, I can see the cursor going to each and every line. Both
LPPCI0.AddedPages and LPPCI3.OptionButton17 are false. But it does not seem
to be deleting the portions of the document between [transmittal] & [added
pages] and between [added pages] & [cover sheet]. Why???? Does .Delete not
work?

[transmittal], [added pages] & [cover sheet] are all in the .dot template.
The verbiage is not being deleted after the mailmerge.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
M

Marty

Thanks Cindy.

I have some code after that which is listed:


With Selection
.HomeKey Unit:=wdStory
.Find.Execute FindText:="[cover sheet]"
.ExtendMode = True
.Find.Execute FindText:="[cover sheet]"
.Delete
End With

The above code is duplicated for "[transmittal]" and "[added pages]"


And I know that "[cover sheet]" is being deleted. It's just that in the
If...Then clause, deletion does not occur. The verbiage between
"[transmittal]" and "[added pages]" does not get deleted, but "[transmittal]"
and "[added pages]" do.

I'm stumped.

-Marty

Cindy M. said:
Hi =?Utf-8?B?TWFydHk=?=,

When you step into and beyond a find.execute line, does the selection actually
change to select, for example, [transmittal]?

You aren't specifying most of the Find properties and methods (ClearFormatting
being important, among others). When you use the Selection object with Find,
any and everything set in the Find dialog will be applied. Such as MatchCase or
MatchWildcards. Possibly something in the dialog box is making it so things
aren't found?
I have some VBA code:


If LPPCI0.AddedPages.Value <> True Then
With Selection
.HomeKey Unit:=wdStory
.Find.Execute FindText:="[transmittal]"
.ExtendMode = True
.Find.Execute FindText:="[added pages]"
.Delete
End With
End If

If LPPCI3.OptionButton17 <> True Then
With Selection
.HomeKey Unit:=wdStory
.Find.Execute FindText:="[added pages]"
.ExtendMode = True
.Find.Execute FindText:="[cover sheet]"
.Delete
End With
End If

When I step through, I can see the cursor going to each and every line. Both
LPPCI0.AddedPages and LPPCI3.OptionButton17 are false. But it does not seem
to be deleting the portions of the document between [transmittal] & [added
pages] and between [added pages] & [cover sheet]. Why???? Does .Delete not
work?

[transmittal], [added pages] & [cover sheet] are all in the .dot template.
The verbiage is not being deleted after the mailmerge.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)


This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
C

Cindy M.

Hi =?Utf-8?B?TWFydHk=?=,
And I know that "[cover sheet]" is being deleted. It's just that in the
If...Then clause, deletion does not occur. The verbiage between
"[transmittal]" and "[added pages]" does not get deleted, but "[transmittal]"
and "[added pages]" do.
*THAT* I would expect, yes. I read your original message through numerous times
to try to determine if that's what you meant. But you asked whether DELETE
works, so I had to assume *nothing* was being deleted, thus the Find not
executing completely.

When you execute FIND, and it is successful, the selection (or range) moves to
that position. "Extend" won't come into the equation because the selection will
go right to the "found" thing.

You need to work with a pair of ranges; one for the starting point, one for the
ending point. Roughly like this (untested). If you want to see what the various
ranges are doing, stick rngStartTag.Select and rngEndTag.Select in there and
step through the code, switching back to the doc window to see what gets
selected.

Dim rngStartTag as Word.Range
Dim rngEndTag as Word.Range

Set rngStartTag = ActiveDocument.Content
Set rngEndTag = ActiveDocument.Content

If LPPCI0.AddedPages.Value <> True Then
rngStartTag.Find.Execute FindText:="[transmittal]"
rngStartTag.Collapse wdCollapseEnd
Set rngEndTag.Start = rngStartTag.End
rngEndTag.Find.Execute FindText:="[added pages]"
rngStartTag.End = rngEndTag.Start
rngStartTag.Delete
'To repeat the search, you need to reset the ranges
'Set rngStartTag.End = ActiveDocument.Content.End
'Set rngEndTag = rngStartTag.Duplicate
End If


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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