Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.newusers
|
|||
|
|||
Doing Character Replace
I have the character sequence "a2M". I want to do a replace of this in my document (a hundred instances at least) in which 'a' becomes the alpha character (Symbol font most likely) and '2' is subscripted. But if I set 'a2M' for symbol font, EVERYTHING becomes symbol font. And if I try to set just '2' for subscripting, every character is subscripted. How is this done? |
#2
Posted to microsoft.public.word.newusers
|
|||
|
|||
Doing Character Replace
If you mean you wish to replace a2M with a formatted version then copy the
manually formatted version to the clipboard and replace a2M with ^c If however you wish to replace sequences *like* a2M with formatted versions of them you are going to need a macro - something like the following. Add case statements for each first character's replacement. The second character is subscripted and the third ignored. Dim oRng As Range With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.Text = "" .Replacement.ClearFormatting Do While .Execute("[a-z][0-9][A-Z]", _ MatchWildcards:=True) Set oRng = Selection.Range Select Case oRng.Characters(1) Case "a" oRng.Characters(1).Text = Chr(97) oRng.Characters(1).Font.name = "Symbol" Case "b" oRng.Characters(1).Text = Chr(98) oRng.Characters(1).Font.name = "Symbol" 'etc Case Else End Select oRng.Characters(2).Font.Subscript = True Loop End With End With 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 "Bjk" wrote in message ... I have the character sequence "a2M". I want to do a replace of this in my document (a hundred instances at least) in which 'a' becomes the alpha character (Symbol font most likely) and '2' is subscripted. But if I set 'a2M' for symbol font, EVERYTHING becomes symbol font. And if I try to set just '2' for subscripting, every character is subscripted. How is this done? |
#3
Posted to microsoft.public.word.newusers
|
|||
|
|||
Doing Character Replace
Hi Bjk,
You could do it with a macro like: Sub ApplySuperscriptNumbers() Dim oRng As Range, fRng As Range, bState As Boolean Application.ScreenUpdating = False Select Case MsgBox("Do you want to process the whole document?", _ vbYesNoCancel + vbQuestion, "Number Superscripter") Case vbYes bState = True Case vbNo bState = False Case vbCancel End End Select With Selection Set oRng = .Range With .Find .ClearFormatting .Text = "[A-Za-z][0-9]{1,}[A-Za-z]" .MatchWildcards = True .Wrap = wdFindContinue .Forward = True Do While .Execute = True Set fRng = ActiveDocument.Range(Start:=Selection.Start + 1, End:=Selection.End - 1) If bState = False Then If fRng.Start = oRng.End Then Exit Do If fRng.End = oRng.End Then fRng.End = oRng.End End If fRng.Font.Superscript = True fRng.Collapse Direction:=wdCollapseEnd Loop End With End With oRng.Select Set fRng = Nothing Set oRng = Nothing Application.ScreenUpdating = True End Sub Note: As coded, the macro will only work with numbers (of any length) between two or more letters. If that's not quite what you require, post back. -- Cheers macropod [Microsoft MVP - Word] "Bjk" wrote in message ... I have the character sequence "a2M". I want to do a replace of this in my document (a hundred instances at least) in which 'a' becomes the alpha character (Symbol font most likely) and '2' is subscripted. But if I set 'a2M' for symbol font, EVERYTHING becomes symbol font. And if I try to set just '2' for subscripting, every character is subscripted. How is this done? |
#4
Posted to microsoft.public.word.newusers
|
|||
|
|||
Doing Character Replace
Correct the "a2M" in one place in your document and copy it. In the find
what box, type a2M. In the replace with box type ^c. The "^c" is the code for the contents of the clipboard. Pam Bjk wrote: I have the character sequence "a2M". I want to do a replace of this in my document (a hundred instances at least) in which 'a' becomes the alpha character (Symbol font most likely) and '2' is subscripted. But if I set 'a2M' for symbol font, EVERYTHING becomes symbol font. And if I try to set just '2' for subscripting, every character is subscripted. How is this done? -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...neral/200912/1 |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Find and Replace Character | Microsoft Word Help | |||
replace a special character | New Users | |||
Find and replace a character | Microsoft Word Help | |||
replace @ character in word | Microsoft Word Help | |||
Designating "Any Character" in Replace Dialog | Microsoft Word Help |