PDA

View Full Version : Superscript part of a WORD in WORD



goraiders
11-13-2012, 09:33 AM
Hi All,

I'd very much appreciate some assistance with this problem I am having. I am aware of a solution for this in Excel VBA, but it doesn't seem to work in Word VBA. Here is my question

1) Is it possible to superscript part of a word or in my case a field (see code below)?

I've tried to use the following code but I am very much a VBA beginner and don't really know how to go about it

ActiveDocument.Variables("VolumeFlow").Value = "ft3/hour
"
ActiveDocument.Variables("VolumeFlow")=Selection.Characters(Start:=3, Length:=1).Font.Superscript = True

It gives me a "Compile Error. Named Argument Not Found" and highlights the "Start:=" segment. I'm confident this works in Excel for a cell, but obviously not here.

I know the variable "VolumeFlow" works as it provides me with the "ft3/hour" value

Any help would be appreciated.

macropod
11-14-2012, 04:50 AM
You cannot format the content of a document variable - only the content of the document itself. For that, you could use a macro like:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "ft3/hour"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
Do While .Find.Found
.Characters(3).Font.Superscript = True
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
Application.ScreenUpdating = True
End Sub

goraiders
11-14-2012, 08:16 AM
Macropod.

Much thanks for your recommendation. I'll give it a shot, it makes sense to me so it should work!

Thanks again.