PDA

View Full Version : Solved: find and replace



rien
03-20-2009, 11:52 PM
Please help,

Who can help me,
I have the following problem: I have to copy/paste a file into a word document but this document it has a page number (Ex. 1 of 6, 2 of 6. etc. etc.).this rule is not in the footer.
Is it possible with VBA to remove the page numbers from the pasted document?

gr.Rien

lucas
03-21-2009, 02:58 PM
Is 1 of 6 , 2 of 6, etc. just a string?

Is it always X of 6?

rien
03-22-2009, 01:08 AM
Lucas,


I send you the file that I will be using paste in the document
This report consists of several pages this time there are 6, but it may also be more.


Thanks for your help,

best regards

Rien

lucas
03-22-2009, 05:56 AM
One way I see to do this is to search for the word "Page" and delete that sentence. I searched your doc and found no other instances of the word before I tried it. You may have to do that before you use this:

Option Explicit
Sub FindWordDeleteSentence()
Dim aRange As Range
Set aRange = ActiveDocument.Range
With aRange.Find
Do
.Text = "Page" ' the word I am looking for
.Execute
If .Found Then
aRange.Expand Unit:=wdSentence
aRange.Delete
aRange.Collapse wdCollapseEnd
End If
Loop While .Found
End With
Set aRange = Nothing
End Sub

rien
03-22-2009, 08:47 AM
Hi Lucas,


This works well, thanks for your help. Where can I report that the problem is solved.


friendly greetings from holland.

Rien:thumb

lucas
03-22-2009, 10:04 AM
You're welcome.. You can mark your thread solved using the thread tools at the top of the page.

Charlize
03-25-2009, 06:13 AM
It would be gratefull if you (Rien) would put a link http://www.vbaexpress.com/forum/showthread.php?t=25810 on the original thread so that we wouldn't waste time on a thread that has been solved but asked at another place in this forum.

Charlize