#1
|
|||
|
|||
Find superscript numbers with a prefix of some default text
Hi!
I have to find "Ref.[sup]2[/sup]", etc. i.e., default text "Ref." with superscript numbers. I can find "Ref." and superscript numbers separately. But, I don't know, how to find them combined. Anybody please help! Regards Alex |
#2
|
|||
|
|||
Do it in two steps.
First, temporarily underline any “Ref.+number” string with red: 1. Find What: Ref.^# 2. Replace With: ^& + Format=red underline Then, search for red underlined text that is superscripted. This will give you all superscripted numbers associated with “Ref.”. When you have finished dealing with the superscripted numbers, remove the temporary red underline. HTH. Cheers, Robert |
#3
|
||||
|
||||
If you are looking for sequences like
Ref.[sup]2[/sup] to replace with Ref.2 (with the 2 superscripted) then the following macro will do that. (http://www.gmayor.com/installing_macro.htm) Code:
Sub ReplaceSuperscript() Dim oRng As Range Const strList As String = "0123456789" Set oRng = ActiveDocument.Range With oRng.Find Do While .Execute(FindText:="Ref.[sup]") oRng.MoveEndUntil "]" oRng.End = oRng.End + 1 oRng.Text = Replace(oRng.Text, "[sup]", "") oRng.Text = Replace(oRng.Text, "[/sup]", "") oRng.MoveStartUntil strList oRng.Font.Superscript = True oRng.Collapse 0 Loop End With lbl_Exit: Exit Sub End Sub Code:
Sub FindSuperscript() Dim oRng As Range Const strList As String = "0123456789 " Set oRng = ActiveDocument.Range With oRng.Find Do While .Execute(FindText:="Ref.") oRng.MoveEndWhile strList 'Do something with the found text e.g. oRng.HighlightColorIndex = wdYellow oRng.Collapse 0 Loop End With lbl_Exit: Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#4
|
|||
|
|||
Your question was asked and answered yesterday in the VBA Express forum. When you cross-post please have the courtesy to indicate that fact in your post. Otherwise as evidenced here people waste their valuable time giving your assistance for free!!
Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim oRng As Word.Range Set oRng = ActiveDocument.Range With oRng.Find .Text = "Ref." While .Execute Do While oRng.Characters.Last.Next Like "[0-9]" _ And oRng.Characters.Last.Next.Font.Superscript oRng.MoveEnd wdCharacter, 1 Loop oRng.Select 'Do something with the found range. oRng.Collapse wdCollapseEnd Wend End With lbl_Exit: Exit Sub End Sub |
#5
|
|||
|
|||
Quote:
Sorry! I didn't mention it before, but, I need to do this by macro. When I record macro, it didn't meet the requirement... Regards Alex |
#6
|
|||
|
|||
The above macro is finding both with/without superscript number along with the text "Ref."
|
#7
|
|||
|
|||
Which above macro? There are three:
Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim oRng As Word.Range Set oRng = ActiveDocument.Range With oRng.Find .Text = "Ref." While .Execute Do While oRng.Characters.Last.Next Like "[0-9]" _ And oRng.Characters.Last.Next.Font.Superscript oRng.MoveEnd wdCharacter, 1 Loop If Len(oRng.Text) > 4 Then oRng.Select 'Do something with the found range. End If oRng.Collapse wdCollapseEnd Wend End With lbl_Exit: Exit Sub End Sub |
#8
|
|||
|
|||
Thanks a lot!!!
It works fine...!!! Regards Alex |
Tags |
find, numbers, superscript |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Find and replace BETWEEN numbers | WordUser2015 | Word | 4 | 12-19-2014 02:09 PM |
Show Page Numbers by default | zamani_2012 | Word | 1 | 06-09-2014 06:09 AM |
Macro to find text only footnote numbers | TimFromPhx | Word VBA | 7 | 04-10-2014 07:05 PM |
Find and replace page numbers in body of text | tollanarama | Word | 3 | 02-13-2011 06:00 AM |
Find & Replace words with "/" prefix & suffix | tollanarama | Word | 4 | 01-25-2011 02:19 AM |