Thanks for your help. When I try to adapt that code so it loops through my cells to figure out what it is finding/replacing. I am getting an error that highlights the .find and says argument not optional, here:
'Now search all other stories using Ranges
For Each myStoryRange In Word.Application.ActiveDocument.StoryRanges
Select Case myStoryRange.StoryType
Case 5, 6, 7, 8, 9
With myStoryRange.Find
This is what i tried to add to what you gave me.
Sub FasterFindAndReplaceAllStoriesHopefully()
Dim myStoryRange As Range
Dim xlApp As Excel.Application
Dim xlWs As Excel.Worksheet
Dim wdApp As Word.Application
Dim lastrow As Long
lastrow = Cells.SpecialCells(xlCellTypeLastCell).Row 'this version of last row looks in any column for the furthest down cell with data in it
Dim wdDoc As Word.Document
Dim pfindtext As String
Dim preplacetext As String
Dim lngjunk As Long
Dim oShp As Word.Shape
Dim newfn$
Dim FileA As String
newfn = Application.GetOpenFilename(Title:="Please select a file")
If newfn = "False" Then Exit Sub
FileA = Word.Application.ActiveDocument.Name
'determine if there are more procedures than word pages to fill in
Dim ival As Integer ' count # of procedures listed (just to see if any were added)
ival = Excel.Application.WorksheetFunction.CountIf(Range("A1:A" & lastrow), "%%Location*%%")
If ival > 3 Then
Warning = MsgBox("Warning, more than 3 procedures!")
Warning = Warning & vbNewLine
Warning = Warning & MsgBox("Have you added extra pages in the word doc?", vbYesNo)
If Warning = vbNo Then Exit Sub
End If
'loop through cells and replace in word
For i = 2 To lastrow
pfindtext = xlWs.Cells(i, 1).Value
preplacetext = xlWs.Cells(i, 2).Value
'wdCommentsStory 4, wdEndnotesStory 3, wdEvenPagesFooterStory 8, wdEvenPagesHeaderStory 6,
'wdFirstPageFooterStory 11, wdFirstPageHeaderStory 10, wdFootnotesStory 2, wdMainTextStory 1,
'wdPrimaryFooterStory 9, wdPrimaryHeaderStory 7, and wdTextFrameStory 5
'First search the main document using the Selection
With wdApp.Selection.Find
.text = strFind
.Replacement.text = strreplace
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
'Now search all other stories using Ranges
For Each myStoryRange In Word.Application.ActiveDocument.StoryRanges
Select Case myStoryRange.StoryType
Case 5, 6, 7, 8, 9
With myStoryRange.Find
.text = strFind
.Replacement.text = strreplace
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Do While Not (myStoryRange.NextStoryRange Is Nothing)
Set myStoryRange = myStoryRange.NextStoryRange
With myStoryRange.Find
.text = strFind
.Replacement.text = strreplace
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Loop
End If
End Select
Next myStoryRange
Next i
End Sub
Is it something i am doing wrong between the applications?
Bookmarks