Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-27-2012, 11:05 AM
Ulodesk Ulodesk is offline Stumped by the recorder again Windows 7 64bit Stumped by the recorder again Office 2010 64bit
Word 2013 Expert Cert
Stumped by the recorder again
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default Stumped by the recorder again

I am trying to create a macro using Word's "Find and select all the highlighted words" ("the" in this trial run) to then copy them and paste into a new document. The macro, which I have tried recording various ways (i.e., from the beginning of the porcess, from having allteh words already highlighted, etc.) fails each time, indicating as the culprit the last line that I have included here, Selection.Copy, wiht a note that nothing is selected. I have had no luck searching or trying to otherwise create a "save selection" command in simpler recorded macros. Can you tell me the trick to this? Thanks in advance.



Code:

Sub Macro1()
'
' Macro1 Macro
'
'
Selection.Find.ClearFormatting
Selection.Find.Highlight = True
With Selection.Find
.Text = "the"
.Replacement.Text = "the"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Copy
Reply With Quote
  #2  
Old 06-27-2012, 02:13 PM
Charles Kenyon Charles Kenyon is offline Stumped by the recorder again Windows Vista Stumped by the recorder again Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Try:
Code:
Sub Macro1() ' 
' Macro1 Macro ' 
' 
Selection.Find.ClearFormatting 
Selection.Find.Highlight = True 
With Selection.Find 
.Text = "the" 
.Replacement.Text = "the" 
.Forward = True 
.Wrap = wdFindContinue 
.Format = True 
.MatchCase = False 
.MatchWholeWord = False 
.MatchWildcards = False 
.MatchSoundsLike = False 
.MatchAllWordForms = False
.Execute
End With 
Selection.Copy
End Sub
Your code sets up the find criteria but doesn't run the find. I haven't tried this, but I've done a lot of coding for replace. I expect it will work.

See How to modify a recorded macro

Last edited by Charles Kenyon; 06-27-2012 at 02:15 PM. Reason: clean up code
Reply With Quote
  #3  
Old 06-29-2012, 09:48 AM
Ulodesk Ulodesk is offline Stumped by the recorder again Windows 7 64bit Stumped by the recorder again Office 2010 64bit
Word 2013 Expert Cert
Stumped by the recorder again
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default No luck

Thanks, Charles. It's an improvement, but unfortunately, it stops after finding the first instance of the word. The rest of my macro copies it and pastes it into the new document. I end up with a new, one-word document.

I have spent well over an hour on this, reading the reference you provided, going into help, running through menus of available properties and actions, etc. etc. Clearly, I will never be any good at this, and I must say, it's awfully frustrating. I have yet to find any source anyhere on beginning VBA that takes an approach that seems obvious to me with respect to providing a useful guide to common sorts of procedures. I say that, despite realizing how vast the options are. My example here typifies the problem: Nowhere can I find a simple indicator of, "Repeat the above for the whole document." I have copied from simple macros in VBA's own Help that should fit nicely, and get nothing but compile errors, term undefined, etc.

Anyway. Any suggestions? I mean, other than giving up entirely and taking a vacation?
Reply With Quote
  #4  
Old 06-29-2012, 11:51 AM
Charles Kenyon Charles Kenyon is offline Stumped by the recorder again Windows Vista Stumped by the recorder again Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

So, if the original document contains the word "the" 280 times, you want a new document with the typed 280 times and nothing else?
thethethethethethethe...

What is it you are trying to accomplish with your macro?
Reply With Quote
  #5  
Old 06-29-2012, 12:09 PM
Ulodesk Ulodesk is offline Stumped by the recorder again Windows 7 64bit Stumped by the recorder again Office 2010 64bit
Word 2013 Expert Cert
Stumped by the recorder again
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default Macro

Well, almost. The words come in, each in its own paragraph, from which I can proceed with table creation, which was to be my next endeavor if I could get this to succeed. From studying other macros, it appeared to me that I could also create a list of words to be found and copied.

This is by no means an urgent task, Charles, rather one of self-education to improve my professional Word skills, so I do not wish to divert your time from assistance to others who may need your expertise more immediately.

Thank you.
Reply With Quote
  #6  
Old 06-29-2012, 11:32 PM
macropod's Avatar
macropod macropod is offline Stumped by the recorder again Windows 7 64bit Stumped by the recorder again Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Perhaps you'd be interested in something like this:
http://www.vbaexpress.com/forum/show...8&postcount=19
or:
https://www.msofficeforums.com/word/...sage-same.html
or:
http://social.technet.microsoft.com/...9-316f76abbe13
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 07-02-2012, 09:23 AM
Ulodesk Ulodesk is offline Stumped by the recorder again Windows 7 64bit Stumped by the recorder again Office 2010 64bit
Word 2013 Expert Cert
Stumped by the recorder again
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default

Thank you. It will take me a good while to digest these, but you have provided much from which to learn.

Philip
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Stumped on Grouping with Custom Fields... ViperMan Project 1 06-22-2011 01:31 AM
Stumped by the recorder again Track chages combine: Stumped! Ulodesk Word 2 01-03-2011 11:43 AM
Stumped- MS Office OLE Links are "Validating". Takes Forever mrbill Office 0 11-09-2010 11:49 AM
Stumped With Mail Merge Formula JennEx Mail Merge 0 05-28-2010 07:44 AM
Help needed using the serial number date with sumifs - whole office is stumped FraserKitchell Excel 3 01-06-2010 12:24 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:43 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft