Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / August 2006

Tip: Looking for answers? Try searching our database.

Does .Delete work in Word2003 11.5604.5606

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marty - 07 Aug 2006 16:07 GMT
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.
Cindy M. - 07 Aug 2006 17:48 GMT
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:
>  
[quoted text clipped - 27 lines]
> [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 :-)
Marty - 07 Aug 2006 18:25 GMT
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

> Hi =?Utf-8?B?TWFydHk=?=,
>
[quoted text clipped - 46 lines]
> This reply is posted in the Newsgroup; please post any follow question or reply
> in the newsgroup and not by e-mail :-)
Cindy M. - 08 Aug 2006 15:56 GMT
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 :-)

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.