I have code that allows me to find and replace a word in a batch of MS word files. Now I would like to have the program print the page that had a word replaced. Can I get some help with where to insert the code below into the find and replace code below that?
This is my code to print the current page:
Application.PrintOut FileName:="", Range:=wdPrintCurrentPage, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=False, PrintToFile:=False
The code for the find and replace is below:
Function Find_Replace(ByRef Doc As Word.Document, ByRef bMatchWC As Boolean, ByRef FindArray As Variant, _
ByRef ReplaceArray As Variant, ByRef bFWWO As Boolean) As String
Dim rngstory As Word.Range
Dim lngJunk As Long
Dim oShp As Shape
Dim x As Long
'Fix the skipped blank Header/Footer problem
lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType
For x = 0 To UBound(FindArray)
'Iterate through all story types in the current document
For Each rngstory In Doc.StoryRanges
'Iterate through all linked stories
Do
SrcAndRplInStory rngstory, FindArray(x), ReplaceArray(x), bMatchWC, bFWWO
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
SrcAndRplInStory oShp.TextFrame.TextRange, _
FindArray(x), ReplaceArray(x), bMatchWC, bFWWO
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
Next x
Find_Replace = Doc.Name & " processed successfully."
Err_ReEntry:
Exit Function
Err_Handler:
Find_Replace = Doc.Name & " failed to process. Error summary: " & Err.Description & "."
Resume Err_ReEntry
End Function
Thanks in Advance
This is my code to print the current page:
Application.PrintOut FileName:="", Range:=wdPrintCurrentPage, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=False, PrintToFile:=False
The code for the find and replace is below:
Function Find_Replace(ByRef Doc As Word.Document, ByRef bMatchWC As Boolean, ByRef FindArray As Variant, _
ByRef ReplaceArray As Variant, ByRef bFWWO As Boolean) As String
Dim rngstory As Word.Range
Dim lngJunk As Long
Dim oShp As Shape
Dim x As Long
'Fix the skipped blank Header/Footer problem
lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType
For x = 0 To UBound(FindArray)
'Iterate through all story types in the current document
For Each rngstory In Doc.StoryRanges
'Iterate through all linked stories
Do
SrcAndRplInStory rngstory, FindArray(x), ReplaceArray(x), bMatchWC, bFWWO
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
SrcAndRplInStory oShp.TextFrame.TextRange, _
FindArray(x), ReplaceArray(x), bMatchWC, bFWWO
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
Next x
Find_Replace = Doc.Name & " processed successfully."
Err_ReEntry:
Exit Function
Err_Handler:
Find_Replace = Doc.Name & " failed to process. Error summary: " & Err.Description & "."
Resume Err_ReEntry
End Function
Thanks in Advance