VBA

S

Steved

Hello form Steved

I was kindly given this by this group
I copied it and pasted it.
It would not work so I gave it a name (Macro Name)Test
I run it but it come up with highlighting wdstory
a message box came up with Compile error, Invalid Outside
Procedure.
Please what have I not done correctly.
Thankyou.

Dim myrange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="Kalsoy",
MatchCase:=True, Wrap:=wdFindStop,
Forward:=True) = True
Set myrange = Selection.Range
myrange.MoveEnd wdStory
myrange.End = myrange.Paragraphs(2).Range.End - 1
myrange.InsertAfter "Without Fear"
Loop
End With
 
W

Word Heretic

G'day "Steved" <[email protected]>,

check out www.mvps.org/word/FAQs/index.htm

Head straight for the VBA/Macros button. Read the first handful of
articles.

Now, after that you need to use this (minus the quote marks of >
naturally)

Public Sub Terminator()
Dim myrange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="Kalsoy",
MatchCase:=True, Wrap:=wdFindStop,
Forward:=True) = True
Set myrange = Selection.Range
myrange.MoveEnd wdStory
myrange.End = myrange.Paragraphs(2).Range.End - 1
myrange.InsertAfter "Without Fear"
Loop
End With

Set myrange=Nothing
End Sub

There's more, but it would scare you at your stage :)

Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Steved reckoned:
 
S

Steved

Thankyou Steve

I will let you know how I get on.
ps this is my first time in using VBA for word.
 

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