deleting to end of document in VBA

M

Marty

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
 
G

Greg Maxey

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
 
D

Doug Robbins - Word MVP

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


--
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
 
M

Marty

Thanks. It worked just fine.

-Marty

Doug Robbins - Word MVP said:
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


--
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

Marty said:
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
 
M

Marty

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

Greg Maxey said:
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-

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
 

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