K
Kirk Soodhalter
Hi,
I have never worked with VB before and I am simply trying to automate
something I do many times in Word for work. I recorded a macro and
found that I had to make some changes by hand. Basically, the script
removes some formatting from selected text. When I try to run it, it
chokes on the second line with an error reading "Compile Error: Object
Required". Below is the code, could someone take a look and perhaps
explain the proper way to access text from the selection object. MS
help was of no help in explaining this. Thanks so much!
Sub RemoveEndnoteFormatting()
'
' RemoveEndnoteFormatting Macro
'
'
Dim strSelectText As String
Set strSelectText = Selection.Text 'chokes here, highlights variable
Selection.Cut
Selection.TypeText Text:=" "
Selection.PasteSpecial Link:=False, DataType:=wdPasteText,
Placement:= _
wdInLine, DisplayAsIcon:=False
Selection.Find.ClearFormatting
With Selection.Find
.Text = strSelectText
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Font.Superscript = wdToggle
End Sub
I have never worked with VB before and I am simply trying to automate
something I do many times in Word for work. I recorded a macro and
found that I had to make some changes by hand. Basically, the script
removes some formatting from selected text. When I try to run it, it
chokes on the second line with an error reading "Compile Error: Object
Required". Below is the code, could someone take a look and perhaps
explain the proper way to access text from the selection object. MS
help was of no help in explaining this. Thanks so much!
Sub RemoveEndnoteFormatting()
'
' RemoveEndnoteFormatting Macro
'
'
Dim strSelectText As String
Set strSelectText = Selection.Text 'chokes here, highlights variable
Selection.Cut
Selection.TypeText Text:=" "
Selection.PasteSpecial Link:=False, DataType:=wdPasteText,
Placement:= _
wdInLine, DisplayAsIcon:=False
Selection.Find.ClearFormatting
With Selection.Find
.Text = strSelectText
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Font.Superscript = wdToggle
End Sub