Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word - Macro done but one problem

Status
Not open for further replies.

Scotsman71

Programmer
May 28, 2003
8
CA
I've been working on a macro(I've posted about it before) for MS Word, so that if I key in a friends name at a prompt, it will go into a text file, find his name and address and paste it for me. I'm ALMOST there :)

The macro is below. The problem with it is this part:

With Selection.Find
.Text = "Michael Smith"

You see, instead of putting the text Michael Smith there, it has to paste the clipboard. So I am doing a find, and I want it to paste the clipboard text in there. How would I do that?

Selection.HomeKey Unit:=wdLine
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Friend:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=3
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Copy
ChangeFileOpenDirectory "C:\"
Documents.Open FileName:="address.txt", ConfirmConversions:=False, ReadOnly _
:=False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate _
:="", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="" _
, Format:=wdOpenFormatAuto, Encoding:=1252
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Michael Smith"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveUp Unit:=wdLine, Count:=2
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=5, Extend:=wdExtend
Selection.Copy
ActiveWindow.Close
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.PasteAndFormat (wdPasteDefault)
 
The help files show the syntax is:

object.paste

but this doesn't seem to work for the clipboard.

You might also try:

object.getfromclipboard

 
I couldn't get either of those to work....and I've poured over my VBA for Dummies book and can't figure out it... :-( Anyone?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top