macro to change text to superscript

  • Thread starter Thread starter Alison Hobbs
  • Start date Start date
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?
 
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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
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

My web site www.gmayor.com

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

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?
 
You are welcome :)

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

My web site www.gmayor.com

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


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

My web site www.gmayor.com

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

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?
 
Hi,
How would you change this to include the find of normal brackets () with a number insde of them?
 
Back
Top