View Single Post
  #7   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Find (w/format) but replace (w/o format)

The macro recorder will not record formatting, but you can use something
similar to the following
The macro uses 2 arrays for the find and replacement texts. Each array here
has four entries in quotes separated by commas.
The superscripted item in the first array is replaced by the
mon-superscripted corresponding item in the second array

Sub ReplaceExample()
Dim vFindText As Variant
Dim vReplText As Variant
Dim i As Long

vFindText = Array("(1)", "(2)", "(3)", "(4)")
vReplText = Array("(Jones, 2008)", "(Smith, 2007)", "(Bloggs, 2005)",
"(Jones, 2009)")
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
'**********************
.Font.Superscript = True
.Replacement.Font.Superscript = False
'**********************
.Forward = True
.Wrap = wdFindContinue
.format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
For i = LBound(vFindText) To UBound(vFindText)
.Text = vFindText(i)
.Replacement.Text = vReplText(i)
.Execute Replace:=wdReplaceAll
Next i
End With
End With
End Sub

http://www.gmayor.com/installing_macro.htm


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



Sharon wrote:
It works great, but I guess I should have told you that I am trying
to put this in a macro. Basically, I have a huge document with
references, i.e., (1), (2), (3), etc. with endnotes that show the
full cite. I want to activate a macro that will change (1) to
(Jones, 2008), which is the short cite. Sorry, I thought it would
work the same when I tried to record the macro. Any suggestions?

From the replace function
Find 'word' - format font superscript (check the superscript check
box in the font dialog)
replace with
^&
format font not superscript/subscript (uncheck the superscript)
check box in the font dialog

CTRL+Shift+ '+' with the cursor in the find or replace boxes will
toggle through the superscript options.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



Sharon wrote:
I want to find a word that is superscript and replace it with a word
that is not superscript, but the "no formatting" button is greyed
out after I put the superscript for the find word. Can anyone help?