VBA Ending a Search

B

Brenda A Reid

I need some vba scripting that would search for the filename field (in both
main document and headers and footers) and replace it with a filename field
(that includes no path) and automatically quit the macro after no more
occurrences of a filename field are found.

I can get it to work but can't get it to loop successfully and then quit
when it reaches the end of the document.

Any help would be appeciated.

Brenda
 
G

Greg Maxey

Sub ScracthMacro()
Dim pRange As Word.Range
Dim oFld As Field
Dim iLink As Long
iLink =
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.StoryType
For Each pRange In ActiveDocument.StoryRanges
For Each oFld In pRange.Fields
Select Case oFld.Type
Case wdFieldFileName
oFld.ShowCodes = True
oFld.Code.Text = Replace(oFld.Code.Text, "\p", "")
oFld.ShowCodes = False
oFld.Update
Case Else
'Do Nothing
End Select
Next
Next
End Sub

I need some vba scripting that would search for the filename field
(in both main document and headers and footers) and replace it with a
filename field (that includes no path) and automatically quit the
macro after no more occurrences of a filename field are found.

I can get it to work but can't get it to loop successfully and then
quit when it reaches the end of the document.

Any help would be appeciated.

Brenda

--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org


McCain/Palin '08 !!!
 

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