Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-19-2017, 07:27 AM
OfficeAssociate99 OfficeAssociate99 is offline Word VBA to search for bold text within a table Windows 7 64bit Word VBA to search for bold text within a table Office 2010 64bit
Novice
Word VBA to search for bold text within a table
 
Join Date: May 2017
Posts: 19
OfficeAssociate99 is on a distinguished road
Default Word VBA to search for bold text within a table


Hi guys,
I'm a newcomer to VBA, so I'm sorry if the formatting is nonstandard. I trying to write a code that finds bold text within all rows of a table (NOT cells OR columns). Then, if the text is a series of known values, then it moves into the next row. If it is not, then the program should recognize this. Right now, I seem to be stuck in an infinite loop, but even before that, it would not return the values I am was looking for.

Code:
 
Dim rw1 As Object
Dim G As Integer
For i = 1 To ActiveDocument.Tables(1).Rows.Count
  
   Set rw1 = ActiveDocument.Tables(1).Rows(1).Range
    With rw1
    With .Find
        With .Font
            .Bold = True
        End With
        .Text = ""
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .Execute
         Do While .Execute
            Set rw1 = ActiveDocument.Tables(1).Rows(i).Next
            If Selection.Find.Font.Bold = True Then
              If Selection.Find.Text = "Organization" Or Selection.Find.Text = "Date" Or Selection.Find.Text = "Description" Or Selection.Find.Text = "Aerospace, Space & Defence" Or Selection.Find.Text = "Automotive" Or Selection.Find.Text = "Manufacturing" Or Selection.Find.Text = "Life Sciences" Or Selection.Find.Text = "Information Communication Technologies / Digital" Or "Natural Resources / Energy" Or Selection.Find.Text = "Regional Stakeholders" Or Selection.Find.Text = "Other Policy Priorities" Then
                G = 5
               Else
                    Selection.Collapse Direction:=wdCollapseStart
                    Selection.MoveDown Unit:=wdLine, Count:=1
                    rng.SetRange Start:=Selection.Start, End:=ActiveDocument.Range.End
                    rng.Select
                    With Selection.Find
                        With .Font
                            .Bold = True
                        End With
                        .Text = "Aerospace, Space & Defence" Or "Automotive" Or "Manufacturing" Or "Life Sciences" Or "Information Communication Technologies / Digital" Or "Natural Resources / Energy" Or "Regional Stakeholders" Or "Other Policy Priorities"
                        .MatchCase = True
                        .MatchWholeWord = True
                        If Selection.Find = True Then
                         MsgBox ("A category has been inserted into the middle of the document. Please copy manually or move extra category to the end of the document to continue automation.")
                            Exit Sub
                        ElseIf Selection.Find.Font.Bold = True Then
                         MsgBox ("There is more than one extra category. Please copy manually.")
                            Exit Sub
                        Else
                            rng.Select
                            Selection.Copy
                            ThisDocument.Activate
                            ThisDocument.Tables(1).Columns(1).Select
                            Selection.Collapse Direction:=wdCollapseEnd
                            Selection.PasteAndFormat (wdTableInsertAsRows)
                        End If
                    End With
              End If
            Else
            G = 6
           End If
     Loop
   End With
   End With
Next i
Reply With Quote
 

Tags
search rows



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word VBA to search for bold text within a table VBA Table – Search All Tables - Find & Replace Text in Table Cell With Specific Background Color jc491 Word VBA 8 09-30-2015 06:10 AM
Word VBA to search for bold text within a table Text in #1 is made bold, rest of the document is edited, text in #1 is now not bold footer-assistance Word 1 06-29-2015 03:49 AM
VBA Search Table for Text/Select Text/Insert Hyperlink sldrellich Word VBA 3 03-24-2015 01:09 PM
how to search and replace BOLD text >> font color change? dylansmith Word 4 03-12-2013 09:51 PM
Word VBA to search for bold text within a table exporting bold text from excel to word? stella@happisburgh.net Excel 3 12-05-2010 08:03 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:06 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