Word 2003 - HELP find replace macro & create userform options?

M

Mal

BIG ask! Ideas on best way to incorporate (write) code based on the MVP code
for find and replace (thank you it is great code so many storys to find and
replace!). I would like to incorporate Screen Updating = False - does that
hinder the find and replace code at all? This is just want I need to do with
a few extra options.



1. Option 1 to create 2 column list and save it as G:\DATA\###### (6 digit
number)



I would also like to create variable lists from templates (separate macro)
and insert the Search For into the left side of the 2 column table doing:

a. CTRL F Find: \[*\]

Check Wildcards

Highlight ALL

b. Copy

c. Call G:\DATA\Find&Replace.doc

d. Paste into Search (1st column table) the variables just copied from
active document screen

e. FILE SAVE AS (regardless of any FILESAVEAS macro) G:\DATA\###### (ask for
6 digit number) to save document

f. Go to 2nd Column 2nd row and give message: "Please enter variable
information"



Search
Replace

[1]
Dalmatian

[2]
Dog

[3]
Overnight

[4]
23 Smith Road, Harbour Village

[5]
United States

[6]
[did not work with returns can I use a semi colon or pipe |] what sort
of code in search & replace would I need to collect this as one replace with
paragraph marks?]

22 Smith Road

HARBOUR VILLAGE

[Name]
Peter John Smith

[NAME]
PETER JOHN SMITH




2. Option 2 to call file number G:\DATA\###### (6 digit number) and edit
data



3. Option 3 to call file number G:\DATA\###### (6 digit number) and perform
loop search/replace



4. Option 4 Code Below



Is it possible to incorporate it in the below code? Would really appreciate
some input to get this userform up and running.



Public Sub FindReplaceAnywhere()

Dim rngStory As Word.Range

Dim pFindTxt As String

Dim pReplaceTxt As String

Dim lngJunk As Long

Dim oShp As Shape

pFindTxt = InputBox("Enter the text that you want to find." _

, "FIND" )

If pFindTxt = "" Then

MsgBox "Cancelled by User"

Exit Sub

End If

TryAgain:

pReplaceTxt = InputBox( "Enter the replacement." , "REPLACE" )

If pReplaceTxt = "" Then

If MsgBox( "Do you just want to delete the found text?", _

vbYesNoCancel) = vbNo Then

GoTo TryAgain

ElseIf vbCancel Then

MsgBox "Cancelled by User."

Exit Sub

End If

End If

'Fix the skipped blank Header/Footer problem

lngJunk = ActiveDocument.Sections( 1 ).Headers( 1 ).Range.StoryType

'Iterate through all story types in the current document

For Each rngStory In ActiveDocument.StoryRanges

'Iterate through all linked stories

Do

SearchAndReplaceInStory rngStory, pFindTxt, pReplaceTxt

On Error Resume Next

Select Case rngStory.StoryType

Case 6 , 7 , 8 , 9 , 10 , 11

If rngStory.ShapeRange.Count > 0 Then

For Each oShp In rngStory.ShapeRange

If oShp.TextFrame.HasText Then

SearchAndReplaceInStory oShp.TextFrame.TextRange, _

pFindTxt, pReplaceTxt

End If

Next

End If

Case Else

'Do Nothing

End Select

On Error GoTo 0

'Get next linked story (if any)

Set rngStory = rngStory.NextStoryRange

Loop Until rngStory Is Nothing

Next

End Sub

Public Sub SearchAndReplaceInStory(ByVal rngStory As Word.Range, _

ByVal strSearch As String , ByVal strReplace As String )

With rngStory.Find

.ClearFormatting

.Replacement.ClearFormatting

.Text = strSearch

.Replacement.Text = strReplace

.Wrap = wdFindContinue

.Execute Replace:=wdReplaceAll

End With

End Sub
 

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