Office & Productivity Software forum

General discussion

Macro for MS word (how to copy/paste and use find function)

by tjohn2 / July 31, 2006 3:33 AM PDT

Hi! I'm using MS Word 2003 and am trying to create a macro to edit a very long file I have. The macro would make it so easy to fix, but I can't figure out how to create it correctly. I've been using the macro recorder so it records my moves. I had copied a word using ctrl+shift+left arrow and then tried to find the word again using the "find" function and then pasting what I had copied into the find function.

When I open the macro, it is looking at the find function with the "text" of my previously copied information, i.e., "ARNP" rather than the new copied/pasted info. (Does this make sense??) I'll paste the macro below for those who may be able to help. (All I want is to be able to find the copied information.)

Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.Copy
Selection.Find.ClearFormatting
With Selection.Find
.Text = "ARNP"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
End Sub

Thanks!

Post a reply
Discussion is locked
You are posting a reply to: Macro for MS word (how to copy/paste and use find function)
The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our CNET Forums policies for details. All submitted content is subject to our Terms of Use.
Track this discussion and email me when there are updates

If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.

You are reporting the following post: Macro for MS word (how to copy/paste and use find function)
This post has been flagged and will be reviewed by our staff. Thank you for helping us maintain CNET's great community.
Sorry, there was a problem flagging this post. Please try again now or at a later time.
If you believe this post is offensive or violates the CNET Forums' Usage policies, you can report it below (this will not automatically remove the post). Once reported, our moderators will be notified and the post will be reviewed.
Collapse -
Alternative.
by Kees Bakker / August 1, 2006 3:46 AM PDT

Although I think it could be done, I don't know how by head, and haven't really the time to research.

So let me suggest an alternative: have a messagebox pop-up where the user can enter (or paste) the search term. Assign the string entered to a variable, and use that in the macro in stead of the string "ARNP". Not really very elegant, but it should work, I expect.

Kees

Collapse -
Correction.
by Kees Bakker / August 1, 2006 5:01 AM PDT
In reply to: Alternative.
Collapse -
My solution
by Merry Goat / September 9, 2010 3:00 AM PDT

Hi
I was having the same problem in a similar application. After a lot of research I found editing just two lines of the macro as follows solved the problem.

Before:
Selection.MoveRight Unit:=wdCharacter, Count:=8, Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToTable, Which:=wdGoToFirst, Count:=2, Name:=""
Selection.Find.ClearFormatting
With Selection.Find
.Text = "AB CD EF"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
End Sub

After:
Selection.MoveRight Unit:=wdCharacter, Count:=8, Extend:=wdExtend
strFindText = Selection.Text
Selection.GoTo What:=wdGoToTable, Which:=wdGoToFirst, Count:=2, Name:=""
Selection.Find.ClearFormatting
With Selection.Find
.Text = strFindText
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
End Sub

Popular Forums
icon
Computer Help 49,613 discussions
icon
Computer Newbies 10,349 discussions
icon
Laptops 19,436 discussions
icon
Security 30,426 discussions
icon
TVs & Home Theaters 20,308 discussions
icon
Windows 10 360 discussions
icon
Phones 15,802 discussions
icon
Windows 7 7,351 discussions
icon
Networking & Wireless 14,641 discussions

Tech explained

Do you know what an OLED TV is?

CNET explains how OLED technology differs from regular TVs, and what you need to know to make the right shopping decision.