Word 2002 Macro - Apply to selected text only

  [DELETED] 15:57 16 Sep 2003

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.


  [DELETED] 16:54 16 Sep 2003

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

  [DELETED] 17:09 16 Sep 2003

This is what I have

Sub supernos()
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

  [DELETED] 17:41 16 Sep 2003

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!

  [DELETED] 19:01 16 Sep 2003


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.

Elsewhere on IDG sites

Microsoft Surface Book 2 15in review

The humble pint glass is redesigned from bottoms up by design legend Sir Kenneth Grange

The best Amazon Prime Day Apple deals 2018

Les meilleures coques pour iPhone X (2018)