G
Greg Maxey
Hi,
I have a snippet of code that applies superscript font:
oWord.SetRange Start:=oWord.Start, End:=oWord.End + 1
oWord.Select
'oWord.Font.Superscript = True
Selection.Font.Superscript = True
I don't understand why I have to select the range and then apply the
formatting to the selection. In another macro I have this code
ActiveDocument.Range.Font.Superscript = True
which I am using to try to solve this riddle. Isn't oWord a Range like
ActiveDocument.Range? Why doesn't oWord.Font.Superscript = True work like
ActiveDocument.Range.Font.Superscript = True
Here is my complete code:
Sub ScratchMacro1()
Dim oPara As Paragraph
Dim oWord As Range
Dim i As Long
Dim myWord As String
Dim mySeq As String
myWord = InputBox("Enter the word to find.")
mySeq = myWord
For Each oPara In ActiveDocument.Paragraphs
i = 0
For Each oWord In oPara.Range.Words
If Right(oWord, 1) = " " Then oWord.MoveEnd Unit:=wdCharacter,
Count:=-1
If LCase(oWord) = LCase(myWord) Then
i = i + 1
oWord.Collapse Direction:=wdCollapseStart
'insert field, reset sequence to 1 for first occurence in paragraph
If i = 1 Then
oWord.Fields.Add Range:=oWord, Type:=wdFieldEmpty, Text:= _
"SEQ " & mySeq & " \r1", PreserveFormatting:=True
Else
'insert field
oWord.Fields.Add Range:=oWord, Type:=wdFieldEmpty, Text:= _
"SEQ " & mySeq & "", PreserveFormatting:=True
End If
'superscript the sequence number
oWord.SetRange Start:=oWord.Start, End:=oWord.End + 1
oWord.Select
'oWord.Font.Superscript = True
Selection.Font.Superscript = True
End If
Next
Next
End Sub
Thanks
I have a snippet of code that applies superscript font:
oWord.SetRange Start:=oWord.Start, End:=oWord.End + 1
oWord.Select
'oWord.Font.Superscript = True
Selection.Font.Superscript = True
I don't understand why I have to select the range and then apply the
formatting to the selection. In another macro I have this code
ActiveDocument.Range.Font.Superscript = True
which I am using to try to solve this riddle. Isn't oWord a Range like
ActiveDocument.Range? Why doesn't oWord.Font.Superscript = True work like
ActiveDocument.Range.Font.Superscript = True
Here is my complete code:
Sub ScratchMacro1()
Dim oPara As Paragraph
Dim oWord As Range
Dim i As Long
Dim myWord As String
Dim mySeq As String
myWord = InputBox("Enter the word to find.")
mySeq = myWord
For Each oPara In ActiveDocument.Paragraphs
i = 0
For Each oWord In oPara.Range.Words
If Right(oWord, 1) = " " Then oWord.MoveEnd Unit:=wdCharacter,
Count:=-1
If LCase(oWord) = LCase(myWord) Then
i = i + 1
oWord.Collapse Direction:=wdCollapseStart
'insert field, reset sequence to 1 for first occurence in paragraph
If i = 1 Then
oWord.Fields.Add Range:=oWord, Type:=wdFieldEmpty, Text:= _
"SEQ " & mySeq & " \r1", PreserveFormatting:=True
Else
'insert field
oWord.Fields.Add Range:=oWord, Type:=wdFieldEmpty, Text:= _
"SEQ " & mySeq & "", PreserveFormatting:=True
End If
'superscript the sequence number
oWord.SetRange Start:=oWord.Start, End:=oWord.End + 1
oWord.Select
'oWord.Font.Superscript = True
Selection.Font.Superscript = True
End If
Next
Next
End Sub
Thanks