G
GolferGuy
I have a need to examine each character in a Word document, and then,
depending on the context, remove a group of characters, change the formatting
of the character or group of characters. But I'm not sure what the objects
are to work my way through all the characters in a document. The code below
is what I have so far, in a testing mode to see what I can learn. One thing
I have learned, is that the first character of a group of characters that are
selected as "superscript" shows as not being superscripted. And one character
past the group shows as being a "superscript" character. I'm thinking I doing
something wrong. Here's my code:
Sub InspectEachCharacter()
Dim x As Integer
Dim MyText As String
ActiveDocument.Select
MyText = Selection
Debug.Print Len(MyText)
ActiveDocument.Characters(1).Select
With Selection
Debug.Print .Text, .Font.Name, .Font.Superscript
End With
For x = 1 To Len(MyText)
Selection.MoveRight unit:=wdCharacter, Count:=1
With Selection
Debug.Print .Text, .Font.Name, .Font.Superscript
'The following three lines of code will cause the whole word that starts
' with "P" to be set to "Superscript"
' But I don't know why????
If .Text = "P" Then
.Font.Superscript = True
End If
End With
Next x
End Sub
depending on the context, remove a group of characters, change the formatting
of the character or group of characters. But I'm not sure what the objects
are to work my way through all the characters in a document. The code below
is what I have so far, in a testing mode to see what I can learn. One thing
I have learned, is that the first character of a group of characters that are
selected as "superscript" shows as not being superscripted. And one character
past the group shows as being a "superscript" character. I'm thinking I doing
something wrong. Here's my code:
Sub InspectEachCharacter()
Dim x As Integer
Dim MyText As String
ActiveDocument.Select
MyText = Selection
Debug.Print Len(MyText)
ActiveDocument.Characters(1).Select
With Selection
Debug.Print .Text, .Font.Name, .Font.Superscript
End With
For x = 1 To Len(MyText)
Selection.MoveRight unit:=wdCharacter, Count:=1
With Selection
Debug.Print .Text, .Font.Name, .Font.Superscript
'The following three lines of code will cause the whole word that starts
' with "P" to be set to "Superscript"
' But I don't know why????
If .Text = "P" Then
.Font.Superscript = True
End If
End With
Next x
End Sub