R
Reuben
Hi - I am very new to macros and VB in particular and I wonder if
someone could help me? I have a basic VB macro set up that I would
like to get resolved and I seem to have drawn a blank. For this
project I am using the generic VB script used for making macros.
Essentially I am trying to automate a procedure for addressing letters
(I am a secretary so that is generally what I do), some of the names
are hyphenated and I know Word sees the hyphenated words as separate.
When I try to run the If statement on the area it comes up with a
"Runtime 424 error, object required" and although I'm sure it is
fairly easy to find a hyphen amongst selected text, it doesn't seem to
want to.
I copy below the part of the macro in question and hopefully someone
could let me know what I am doing wrong.
Selection.Find.ClearFormatting
With Selection.Find
.Text = "-"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
If Find.Found = True Then
Selection.EndKey Unit:=wdLine
Selection.MoveLeft Unit:=wdWord, Count:=3, Extend:=wdExtend
Selection.Copy
GoTo 2
Else:
Selection.EndKey Unit:=wdLine
Selection.MoveLeft Unit:=wdWord, Count:=3, Extend:=wdExtend
Selection.Copy
GoTo 2
End If
Hopefully this doesn't sound too rubbish, I really would appreciate a
hand here if someone could spare one.
Reuben
someone could help me? I have a basic VB macro set up that I would
like to get resolved and I seem to have drawn a blank. For this
project I am using the generic VB script used for making macros.
Essentially I am trying to automate a procedure for addressing letters
(I am a secretary so that is generally what I do), some of the names
are hyphenated and I know Word sees the hyphenated words as separate.
When I try to run the If statement on the area it comes up with a
"Runtime 424 error, object required" and although I'm sure it is
fairly easy to find a hyphen amongst selected text, it doesn't seem to
want to.
I copy below the part of the macro in question and hopefully someone
could let me know what I am doing wrong.
Selection.Find.ClearFormatting
With Selection.Find
.Text = "-"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
If Find.Found = True Then
Selection.EndKey Unit:=wdLine
Selection.MoveLeft Unit:=wdWord, Count:=3, Extend:=wdExtend
Selection.Copy
GoTo 2
Else:
Selection.EndKey Unit:=wdLine
Selection.MoveLeft Unit:=wdWord, Count:=3, Extend:=wdExtend
Selection.Copy
GoTo 2
End If
Hopefully this doesn't sound too rubbish, I really would appreciate a
hand here if someone could spare one.
Reuben