Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Marty Marty is offline
external usenet poster
 
Posts: 28
Default deleting to end of document in VBA

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
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 171
Default deleting to end of document in VBA

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

Marty wrote:
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


  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default deleting to end of document in VBA

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" wrote in message
...
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



  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Marty Marty is offline
external usenet poster
 
Posts: 28
Default deleting to end of document in VBA

Thanks. It worked just fine.

-Marty

"Doug Robbins - Word MVP" wrote:

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" wrote in message
...
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




  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Marty Marty is offline
external usenet poster
 
Posts: 28
Default deleting to end of document in VBA

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" wrote:

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

Marty wrote:
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



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Warn before deleting a Word document ccs Microsoft Word Help 2 June 9th 06 02:26 PM
Deleting text within a document chesko Microsoft Word Help 3 April 20th 06 07:56 PM
deleting a blank page in a document in Word 2003 candice41 Microsoft Word Help 2 April 10th 06 03:16 PM
macros and SharePoint WSS document libraries [email protected] New Users 0 October 6th 05 03:42 AM
deleting identify when saving document Lindow Prof Microsoft Word Help 2 March 4th 05 07:15 PM


All times are GMT +1. The time now is 12:30 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"