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.

deleting to end of document in VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marty - 21 Aug 2006 19:34 GMT
Hi-

I have the following VBA code in a mailmerge:

   With Selection
        .HomeKey unit:=wdStory
        .Find.Execute findtext:="[end of transmittal]"
        .ExtendMode = True
        .Find.Execute findtext:="[end of transmittal]"
        .Delete
   End With

This will delete all text between (and including) "[end of transmittal]".
But, what I really want to do, is to deletle all text from "[end of
transmittal]" to the end of the document.

How would I change the above to accomplish this?

Thanks,
Marty
Greg Maxey - 21 Aug 2006 19:48 GMT
Try:

Sub Scratchmacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng
 With .Find
 .Text = "[end of transmittal]"
 If .Execute Then
   With oRng
     .Collapse wdCollapseEnd
     .End = ActiveDocument.Range.End
     .Delete
   End With
 End If
 End With
End With
End Sub

> Hi-
>
[quoted text clipped - 16 lines]
> Thanks,
> Marty
Marty - 21 Aug 2006 20:41 GMT
I tried this, but it did not seem to work. Perhaps it was not getting to the
beginning of the document. However, Doug also sent some code, and that did
work.

Thanks for you help. It helps me to understand what is happening in the code.

-Marty

> Try:
>
[quoted text clipped - 35 lines]
> > Thanks,
> > Marty
Doug Robbins - Word MVP - 21 Aug 2006 19:58 GMT
This should do it

   Dim delrange as Range
   With Selection
        .HomeKey unit:=wdStory
        .Find.Execute findtext:="[end of transmittal]"
   End With
   Set delrange = Selection.Range
   delrange.Start=delrange.End+1
   delrange.End = ActiveDocument.Range.End
   delrange.Delete

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

> Hi-
>
[quoted text clipped - 16 lines]
> Thanks,
> Marty
Marty - 21 Aug 2006 20:40 GMT
Thanks. It worked just fine.

-Marty

> This should do it
>
[quoted text clipped - 28 lines]
> > Thanks,
> > Marty
 
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.