I'm almost always here. :-)
Adding tables and footnotes to the mix makes the macro considerably longer, but not impossible. By the way, use copy and paste, not retyping, to transfer the code to the VBA editor. I see two typos (if that's what they are) in your last post that would cause
errors -- the variables FixlCommaRng and FixPuncuationRng are not defined.
Try this code with your documents, and let me know if anything else goes wrong. I know, for example, that there could be a problem if a table cell contains an odd number of straight quotes or an unmatched "smart" quote.
Sub TermByTerm()
Dim SearchAndReplaceRng As Range
Dim FixCommaRng As Range
Dim aCell As Cell
Set SearchAndReplaceRng = ActiveDocument.Content
With SearchAndReplaceRng.Find
.ClearFormatting
.Text = "[^0034^0147]*[^0034^0148]" '<-- Search for text between quotes
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
While .Execute
With SearchAndReplaceRng
.MoveEnd Unit:=wdCharacter, Count:=-1
.MoveStart Unit:=wdCharacter, Count:=1
.Select ' <-- bring it into view
.Font.Underline = wdUnderlineSingle
Set FixCommaRng = SearchAndReplaceRng.Duplicate
With FixCommaRng.Find
.Format = True
.Text = ","
.Font.Underline = True
.Replacement.Text = ","
.Replacement.Font.Underline = wdUnderlineNone
.Execute Replace:=wdReplaceAll
End With
If MsgBox(Prompt:="Continue?", Buttons:=vbYesNo) = vbNo Then
If MsgBox(Prompt:="Check footnotes?", Buttons:=vbYesNo) = vbYes Then
GoTo SearchFootnotes
Else
Exit Sub
End If
End If
If .Information(wdWithInTable) Then
Set aCell = .Tables(1).Cell( _
.Information(wdEndOfRangeRowNumber), _
.Information(wdEndOfRangeColumnNumber))
If .End < aCell.Range.End - 3 Then
.Start = .End + 2
.End = aCell.Range.End - 1
Else
On Error GoTo LeaveTable
.Start = aCell.Next.Range.Start
.End = aCell.Next.Range.End - 1
While InStr(aCell.Range.Text, Chr(34)) = 0 And InStr(aCell.Range.Text, Chr(147)) = 0
Set aCell = aCell.Next
Wend
End If
GoTo MyResume
LeaveTable:
Err.Clear
.Start = .Tables(1).Range.End + 1
.End = ActiveDocument.Content.End
MyResume:
Else
.Start = .End + 2 ' <-- next search starting after the current closing quote
.End = ActiveDocument.Content.End ' <-- and continuing to the end of the document
End If
End With
Wend
End With
SearchFootnotes:
Set SearchAndReplaceRng = ActiveDocument.StoryRanges(wdFootnotesStory)
With SearchAndReplaceRng.Find
.ClearFormatting
.Text = "[^0034^0147]*[^0034^0148]" '<-- Search for text between quotes
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
While .Execute
With SearchAndReplaceRng
.MoveEnd Unit:=wdCharacter, Count:=-1
.MoveStart Unit:=wdCharacter, Count:=1
.Select ' <-- bring it into view
.Font.Underline = wdUnderlineSingle
Set FixCommaRng = SearchAndReplaceRng.Duplicate
With FixCommaRng.Find
.Format = True
.Text = ","
.Font.Underline = True
.Replacement.Text = ","
.Replacement.Font.Underline = wdUnderlineNone
.Execute Replace:=wdReplaceAll
End With
If MsgBox(Prompt:="Continue?", Buttons:=vbYesNo) = vbNo Then Exit Sub
.Start = .End + 2 ' <-- next search starting after the current closing quote
.End = ActiveDocument.StoryRanges(wdFootnotesStory).End ' <-- and continuing to the end of the document
End With
Wend
End With
End Sub