help for extreme newbie

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
 
J

Jonathan West

Hi Kirk,

Remove the word "Set". You only use Set when you want to assign an object.
Strings dates and numbers are not objects.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top