Pasting Clipboard Text to Search/Find

J

jsouriane

In Word, I wish to create the following macro and it doesn’t work:

Before using the macro, I merge a document. There is a place where I
bookmarked a field, so once the merge done, the bookmark is still
there.

I want the macro to go get the words in the bookmark, copy it, open a
Document (Name Known) and search for the copied words.

Once it has found the words, my macro will continue with something
else but I am just not able to get there. Can you help me someone?
Thank you!!

HERE is that part of the macro so far:

Selection.InsertCrossReference ReferenceType:="Signet",
ReferenceKind:= _
wdContentText, ReferenceItem:="NAME_OF_MY_BOOKMARK",
InsertAsHyperlink:=False, _
IncludePosition:=False, SeparateNumbers:=False,
SeparatorString:=" "
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Selection.Copy

Dim CopiedWord
CopiedWord = Selection.Text

'Opens the Second document where to search in:
Documents.Open FileName:="""c:\temp\Document.doc"""
Selection.HomeKey Unit:=wdStory


Selection.Find.ClearFormatting
With Selection.Find
.Text = CopiedWord
End With
Selection.Find.Execute
 
S

Steve Yandl

One thing you might try to change is the way you retrieve the text contained
by your bookmark. The following will capture the text in the active
document in a bookmark named myMark.

Dim strBookmark As String
strBookmark = ActiveDocument.Bookmarks("myMark").Range.Text
MsgBox strBookmark


Steve Yandl


In Word, I wish to create the following macro and it doesn’t work:

Before using the macro, I merge a document. There is a place where I
bookmarked a field, so once the merge done, the bookmark is still
there.

I want the macro to go get the words in the bookmark, copy it, open a
Document (Name Known) and search for the copied words.

Once it has found the words, my macro will continue with something
else but I am just not able to get there. Can you help me someone?
Thank you!!

HERE is that part of the macro so far:

Selection.InsertCrossReference ReferenceType:="Signet",
ReferenceKind:= _
wdContentText, ReferenceItem:="NAME_OF_MY_BOOKMARK",
InsertAsHyperlink:=False, _
IncludePosition:=False, SeparateNumbers:=False,
SeparatorString:=" "
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Selection.Copy

Dim CopiedWord
CopiedWord = Selection.Text

'Opens the Second document where to search in:
Documents.Open FileName:="""c:\temp\Document.doc"""
Selection.HomeKey Unit:=wdStory


Selection.Find.ClearFormatting
With Selection.Find
.Text = CopiedWord
End With
Selection.Find.Execute
 
G

guylaine.constant

Thank you very much Steve. It did solve my problem.

I've been searching for hours!

Thanks thanks thanks!!!

S.
 
Top