![]() |
|
#2
|
|||
|
|||
|
I'm afraid your code does have a lot of errors both structural and logical so it would never work as you intended.
What do you want to happen if no bold text with a key term is found in a row? What do you want to happen if a key term in bold is found? Some hints are 1. Use F1 to get help on any VBA term 2. In the IDE use Tools.options and tick all the boxes under Code Settings The code below might help to point you in the right direction Code:
Sub sbSearchRowsForBold()
' Consolidate into a single string so we can search using instring to check if the found text is a Key Term
' 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
' Some of the text entries include ',' so + is used as a separator
Const myKeyTerms As String = _
"OrganizationDate+Description+Aerospace, Space & Defence+Automotive+Manufacturing+Life Sciences+Information Communication Technologies / Digital+Natural Resources / Energy+Regional Stakeholders+Other Policy Priorities"
Dim myTable As Table
Dim myRow As Row
Dim myRange As Range
For Each myTable In ActiveDocument.Tables
For Each myRow In myTable.Rows
' If successful myrange is moved to the found text
Set myRange = myRow.Range
' Search parameters are persistent so you only need to change them if the search parameters change
With myRange.Find
.Font.Bold = True
.Text = ""
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.Wrap = wdFindStop
.Forward = True
' Stop when the range is searched
' .Execute returns true if the search is found
Do While .Execute
' myRange is now the found term
Debug.Print "Bold text is found ->" & myRange.Text
' for learning purposes the select statement below shows the new range for myrange
myRange.Select
If InStr(myKeyTerms, myRange.Text) > 0 Then
'Actions to do if the row contained a key term in bold
Debug.Print "Found a key term in bold " & myRange.Text
' Continue searching
Else
'Actions to do is the row does not contain bold text
Debug.Print "No key terms found in bold text"
End If
' now we need to reset myRange to encompass the rest of the row
myRange.Start = myRange.End + 1
myRange.End = myRow.Range.End
' again for learning see where myRange has moved
myRange.Select
Loop
End With
Next myRow
Next myTable
End Sub
|
| Tags |
| search rows |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
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 |
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 |
exporting bold text from excel to word?
|
stella@happisburgh.net | Excel | 3 | 12-05-2010 08:03 AM |