Word 2002 Macro - Apply to selected text only

  tend-to-panic 15:57 16 Sep 03
Locked

I want to turn all numbers in a pre-selected paragraph into superscript font without changing the numbers in the rest of the document.

I do not know Visual Basic (yet!) so use Record a Macro. I do the necessary ReplaceAll which only affects the previously selected text, answer "No" when it asks if this should be applied to rest of document then stop macro recording. All is well -selected text has been changed as required, rest of text left unaltered.

However, when macro is run it changes all the numbers in the whole document to superscript, not just those in the selected text.

How do I get the macro to only apply to the text I have selected before running it. As I said, what I do works fine during the recording of the macro!

Would really appreciate some advice.

Thanks!

  VoG II 16:54 16 Sep 03

Can you post the macro code created?

What you need to do is modify it so that it refers to the selection - see click here

  tend-to-panic 17:09 16 Sep 03

This is what I have

Sub supernos()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find.Replacement.Font
.Superscript = True
End With
With Selection.Find
.Text = "[0-9]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

  VoG II 17:41 16 Sep 03

I've just run your macro and it only applied the changes to the area of text that I selected!

It then tells me how many it has found and changed, do I want to search the rest of the document.

So, I'm baffled!

  tend-to-panic 19:01 16 Sep 03

VoG

Thank you veru much for your help.

After reading your second posting when you said it worked for you, I thought I would just try the macro (unaltered)once again on the same file, same bit of text and this time, much to my surprise as I had earlier spent 45 mintues with it not doing its thing, it worked! I had, however, rebooted the PCC in between originally trying to get macro to work and reading your second posting. I too am baffled - perhaps something odd glitch happened with Word or Office and rebooting sorted it out.

I am sorry to have wasted your time - thank you for pointing me to the help file on selection - I will get to grips with it in due course.

This thread is now locked and can not be replied to.

Qualcomm Snapdragon 835 benchmarks: Antutu, Geekbench 4, GFXBench and PCMark results

1995-2015: How technology has changed the world in 20 years

This stop-frame animation tells a moving story of domestic violence for Refuge

New iPad 2017 preview: Apple's affordable but underspecced new iPad may appeal to the education…