#1
|
|||
|
|||
How to check for the higest superScript number, that is NOT red?
I'm writing a script that needs to find all superScript numbers in the document, that are NOT red, and get the highest number found. Here's what I have so far, but I don't know how to process the find to check if the found character is red, or how to retrieve the number it found. I'm thinking I need a loop during the find to check it's font color and text. But I'm stumped how to do that. Code:
With rng_selection.Find .Font.Superscript = True ' Only find superScripts .Text = "[0-9]" ' Find only numbers .MatchWildcards = True .Execute End With |
#2
|
||||
|
||||
For example:
Code:
Sub Demo() Application.ScreenUpdating = False Dim i As Long With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Format = False .Forward = True .Font.Superscript = True .Wrap = wdFindStop .MatchWildcards = True .Text = "<[0-9]@>" .Replacement.Text = "" End With Do While .Find.Execute = True If .Font.ColorIndex <> wdClassicRed Then If .Text > i Then i = .Text End If .Collapse wdCollapseEnd Loop End With MsgBox i Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thanks Macropod! That's exactly what I was looking for.
I did have a problem with using .Text = "<[0-9]@>" It would only report 3, even though I had numbers up to 9 in the doc. I changed it to .Text = "[0-9]" and it's behaving as expected. I'm not sure what the version you recommended does, or maybe I need to do something different to allow that? I am setting the Red to RGB values as 255,0,0. Which ends up being wdRed. |
#4
|
||||
|
||||
Using just [0-9] will only find single digits (i.e. 0-9), excluding 10 and above. If <[0-9]@> isn't working, that suggests you're not looking for numbers, per se, but numeric strings that may or may not be part of larger alpha-numeric strings. In that case, use:
.Text = "[0-9]{1,}"
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
That did it! Thank you again! Worked for both single digit and multiple digit superScript numbers.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Char style and footnotes reference style superscript - applying character style removes superscript | RRB | Word | 2 | 06-02-2021 02:54 PM |
Count and display number of spell check errors | Leslie | Word VBA | 3 | 03-01-2020 03:26 AM |
The “spelling and grammar” check fails to work as the number of words in the file exceeds a certain | Jamal NUMAN | Word | 3 | 09-24-2019 10:45 AM |
Footnote reference numbers precede by superscript '(' and follow w/ superscript ')' | Swarup | Word | 4 | 07-18-2019 05:51 PM |
cannot check/uncheck check box but added check box | learn2office | Word | 1 | 11-27-2012 02:02 AM |