Thread: [Solved] Word VBA Capabilities
View Single Post
 
Old 05-18-2019, 12:38 PM
eduzs eduzs is offline Windows 10 Office 2010 32bit
Expert
 
Join Date: May 2017
Posts: 266
eduzs is on a distinguished road
Default

Hi there.
Maybe you can start with something like:
(save/close any other files you're using before testing macros, backup your original file before doing any modification, test in a throwaway copy of your file)
Code:
Sub Find_paragraph_with_string()

Dim x As Integer, oDoc, y As Integer

Set oDoc = ActiveDocument

For x = oDoc.Sections.Count To 1 Step -1
    With oDoc.Sections(x).Range
        For y = 1 To .Paragraphs.Count
            If InStr(.Paragraphs(y).Range.Text, "Hello") > 0 Then MsgBox "Hello! I'm in the " & y & " paragraph of the " & x & " section!"
        Next y
    End With
Next x

End Sub

Sub Find_table_cell_with_string()

Dim x As Integer, oDoc, y As Integer, oCel

Set oDoc = ActiveDocument

For x = oDoc.Sections.Count To 1 Step -1
    With oDoc.Sections(x).Range
        If .Tables.Count > 0 Then
            For y = 1 To .Tables.Count
                For Each oCel In .Tables(y).Range.Cells
                    If Left(oCel.Range.Text, Len(oCel.Range.Text) - 2) = "Hi!" Then MsgBox "Found!"
                Next oCel
            Next y
        End If
    End With
Next x

End Sub
__________________
Backup your original file before doing any modification.
Reply With Quote