Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Paste into find dialog using macros.

0 views
Skip to first unread message

John

unread,
Dec 22, 2009, 9:45:35 PM12/22/09
to
In MS Word 2003 when recording macros and making search using Find and
Replace dialog window it alway's remembers text you use, how can i modify
macros to paste text from clipboard into Find what: field?


Graham Mayor

unread,
Dec 23, 2009, 3:20:01 AM12/23/09
to
The macro recorder is limited in its abilities. To insert text from the
clipboard you would have to manually configure the macro to use text from
the clipboard e.g.

Dim sFindText As String
Dim sReplaceText As String
Dim oClip As DataObject
Set oClip = New DataObject
oClip.GetFromClipboard
sFindText = oClip.GetText
sReplaceText = "The text to replace the found text with"
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = sFindText
.Replacement.Text = sReplaceText
.Forward = True
.Wrap = wdFindContinue
.format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With
End With


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

"John" <Johni...@gmail.com> wrote in message
news:eppoDo3g...@TK2MSFTNGP06.phx.gbl...

John

unread,
Dec 23, 2009, 11:52:09 AM12/23/09
to
Hi, thank you for replay. I tried create macro then remove all code from it
except Sub and End Sub then paste code you posted below and i getting error
when running that macro in Basic editor it highlights this line "oClip As
DataObject". I use Office 2003 on Windows XP SP3.


"Graham Mayor" <gma...@REMOVETHISmvps.org> wrote in message
news:%23R7pzi6...@TK2MSFTNGP06.phx.gbl...

Jay Freedman

unread,
Dec 23, 2009, 1:35:10 PM12/23/09
to
In the VBA editor, click Tools > References. Find "Microsoft Forms 2.0
Object Library" in the list of available references and click to put a
check mark in its box. Click OK. The macro will now run.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.


On Wed, 23 Dec 2009 08:52:09 -0800, "John" <Johni...@gmail.com>
wrote:

0 new messages