Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 05-18-2019, 12:38 PM
eduzs eduzs is offline Word VBA Capabilities Windows 10 Word VBA Capabilities 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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word VBA Capabilities OneNote Software Capabilities hils0590 OneNote 3 12-31-2014 10:35 AM
Word VBA Capabilities Outlook 2010 to CRM capabilities Iain Outlook 1 02-20-2012 10:30 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:30 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft