Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-31-2022, 10:35 AM
BrianHoard BrianHoard is offline How to check for the higest superScript number, that is NOT red? Windows 10 How to check for the higest superScript number, that is NOT red? Office 2019
Advanced Beginner
How to check for the higest superScript number, that is NOT red?
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default 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
Thanks for any help.
Reply With Quote
  #2  
Old 07-31-2022, 04:10 PM
macropod's Avatar
macropod macropod is offline How to check for the higest superScript number, that is NOT red? Windows 10 How to check for the higest superScript number, that is NOT red? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
Of course, since Word has different versions of 'red' (e.g. wdRed, wdClassicRed, wdDarkRed), you'll need to choose the correct one for testing. And, if it's not one of those 'standard' reds, you'll need to use .Font.Color with the appropriate RGB value.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 07-31-2022, 05:11 PM
BrianHoard BrianHoard is offline How to check for the higest superScript number, that is NOT red? Windows 10 How to check for the higest superScript number, that is NOT red? Office 2019
Advanced Beginner
How to check for the higest superScript number, that is NOT red?
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 07-31-2022, 05:16 PM
macropod's Avatar
macropod macropod is offline How to check for the higest superScript number, that is NOT red? Windows 10 How to check for the higest superScript number, that is NOT red? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #5  
Old 07-31-2022, 05:31 PM
BrianHoard BrianHoard is offline How to check for the higest superScript number, that is NOT red? Windows 10 How to check for the higest superScript number, that is NOT red? Office 2019
Advanced Beginner
How to check for the higest superScript number, that is NOT red?
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

That did it! Thank you again! Worked for both single digit and multiple digit superScript numbers.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check for the higest superScript number, that is NOT red? Char style and footnotes reference style superscript - applying character style removes superscript RRB Word 2 06-02-2021 02:54 PM
How to check for the higest superScript number, that is NOT red? 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
How to check for the higest superScript number, that is NOT red? Footnote reference numbers precede by superscript '(' and follow w/ superscript ')' Swarup Word 4 07-18-2019 05:51 PM
How to check for the higest superScript number, that is NOT red? cannot check/uncheck check box but added check box learn2office Word 1 11-27-2012 02:02 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:38 PM.


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