#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
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 See How to modify a recorded macro Last edited by Charles Kenyon; 06-27-2012 at 02:15 PM. Reason: clean up code |
#3
|
|||
|
|||
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? |
#4
|
|||
|
|||
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? |
#5
|
|||
|
|||
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. |
#6
|
||||
|
||||
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] |
#7
|
|||
|
|||
Thank you. It will take me a good while to digest these, but you have provided much from which to learn.
Philip |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Stumped on Grouping with Custom Fields... | ViperMan | Project | 1 | 06-22-2011 01:31 AM |
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 |