I'm writing a program that reads Word text. The text is in tables. Parts of the text in any given cell of the table may be highlighted. Is there an easy way to pick out where the text highlight color starts and stops and also to detect what color is used for the highlighting?
Visual Basic.NETMicrosoft Word
Last Comment
RBECKMN
8/22/2022 - Mon
Rgonzo1971
Hi,
You can adapt that
Sub FindHighlight() ' Make sure you can access the pane properly. Application.ActiveWindow.View = wdNormalView ' Holds the current pane. Dim CurrPane As Pane ' Access the test document pane. Set CurrPane = Application.ActiveWindow.ActivePane ' Go to the beginning of the document. CurrPane.Selection.GoTo wdGoToLine, wdGoToFirst ' Creates a search for the word. Dim DoSearch As Find Set DoSearch = CurrPane.Selection.Find ' Perform the search. With DoSearch ' Clear any existing formatting information. .ClearFormatting .Highlight = True .MatchCase = False .Wrap = wdFindContinue ' Continue until there is nothing else to search. While DoSearch.Execute() With CurrPane.Selection.FormattedText Bgn = .Start Last = .End MsgBox "This highlight begins at " & Bgn & " and ends at " & Last ColorIdx = .HighlightColorIndex End With ' Move to the next character. CurrPane.Selection.Move Count:=1 Wend End With ' Go to the beginning of the document. CurrPane.Selection.GoTo wdGoToLine, wdGoToFirstEnd Sub
You can adapt that
Open in new window
Regards