Skip to content

Instantly share code, notes, and snippets.

@supergrass71
Last active October 27, 2019 09:59
Show Gist options
  • Save supergrass71/de183e7f0c8025ac11b310d3798af824 to your computer and use it in GitHub Desktop.
Save supergrass71/de183e7f0c8025ac11b310d3798af824 to your computer and use it in GitHub Desktop.
Replace In Table #Word
Function ReplaceInTable(textToFind As String) As String
'http://www.msofficeforums.com/word-vba/28049-vba-table-search-all-tables-find-replace.html
Dim oRng As Range
Set oRng = ActiveDocument.Range
'if used as sub add inputbox for texttofind
With oRng.Find
Do While .Execute(FindText:=textToFind)
If oRng.Information(wdWithInTable) Then
oRng.Select
Selection.Cells(1).Next.Select
Set oRng = Selection.Range
ReplaceInTable = CleanTrim(oRng.Text, True)
GoTo lbl_Exit
End If
Loop
End With
lbl_Exit:
'ReplaceInTable = "" 'could not find a reference table
Exit Function
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment