macro to change text to superscript

A

Alison Hobbs

I'm editing a document that has endnotes. They've already been delinked so
the numbers in the text are independent. I want to convert note numbers in
the text from normal text in square brackets, i.e. [1], to superscript, no
brackets, but leave the endnote numbers as they are.

I've got as far as recording a macro using find and replace (with the
endnotes first cut and pasted to a new document) which removes the square
brackets, but I can't figure out how to do the superscript bit.

What I really need is a macro that finds all numbers in square brackets
(from 1 to 100 should pick up most of them) and converts them to superscript,
no brackets. Can anyone help?
 
G

Graham Mayor

The following will work for all numbers in square brackets:

Sub ReplaceExample()
With Selection
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
'**********************
.Text = "\[([0-9]{1,})\]"
.Replacement.Text = "\1"
.Replacement.Font.Superscript = True
'**********************
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchWholeWord = False
.MatchWildcards = True
.Execute replace:=wdReplaceAll
End With
End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Alison Hobbs

That worked perfectly. Many many thanks!

Graham Mayor said:
The following will work for all numbers in square brackets:

Sub ReplaceExample()
With Selection
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
'**********************
.Text = "\[([0-9]{1,})\]"
.Replacement.Text = "\1"
.Replacement.Font.Superscript = True
'**********************
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchWholeWord = False
.MatchWildcards = True
.Execute replace:=wdReplaceAll
End With
End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Alison said:
I'm editing a document that has endnotes. They've already been
delinked so the numbers in the text are independent. I want to
convert note numbers in the text from normal text in square brackets,
i.e. [1], to superscript, no brackets, but leave the endnote numbers
as they are.

I've got as far as recording a macro using find and replace (with the
endnotes first cut and pasted to a new document) which removes the
square brackets, but I can't figure out how to do the superscript bit.

What I really need is a macro that finds all numbers in square
brackets (from 1 to 100 should pick up most of them) and converts
them to superscript, no brackets. Can anyone help?
 
G

Graham Mayor

You are welcome :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Alison said:
That worked perfectly. Many many thanks!

Graham Mayor said:
The following will work for all numbers in square brackets:

Sub ReplaceExample()
With Selection
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
'**********************
.Text = "\[([0-9]{1,})\]"
.Replacement.Text = "\1"
.Replacement.Font.Superscript = True
'**********************
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchWholeWord = False
.MatchWildcards = True
.Execute replace:=wdReplaceAll
End With
End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Alison said:
I'm editing a document that has endnotes. They've already been
delinked so the numbers in the text are independent. I want to
convert note numbers in the text from normal text in square
brackets, i.e. [1], to superscript, no brackets, but leave the
endnote numbers as they are.

I've got as far as recording a macro using find and replace (with
the endnotes first cut and pasted to a new document) which removes
the square brackets, but I can't figure out how to do the
superscript bit.

What I really need is a macro that finds all numbers in square
brackets (from 1 to 100 should pick up most of them) and converts
them to superscript, no brackets. Can anyone help?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top