From: John on 26 Mar 2010 05:52 Hi I tried, and failed to create a macro. (I do a procedure hundreds of times every day so wanted to automate it) I press Control-F (to open the 'find' dialogue) and then press Control- V (to paste the contents) into the dialogue. As you can see from the code below, when I recorded the macro, it used '2022' (which is what happens to be in my clipboard right now) but I want it to use the clipboard. Is this possible? I hope I've explained the problem properly. ==================================================== Sub FindWhatsinClipboard() ' ' FindWhatsinClipboard Macro ' Macro recorded 26/03/2010 by John Smith ' Selection.Find.ClearFormatting With Selection.Find .Text = "2202" .Replacement.Text = "" .Forward = True .Wrap = wdFindAsk .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Find.ClearFormatting With Selection.Find .Text = "2202" .Replacement.Text = "" .Forward = True .Wrap = wdFindAsk .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With End Sub
From: Jay Freedman on 26 Mar 2010 10:12 Hi John, Replace the line .Text = "2202" with .Text = Selection.Text Also, everything the recorder put into the macro after the line Selection.Find.Execute is worthless and can be deleted. For enlightenment, see http://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm. -- 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. John wrote: > Hi > > I tried, and failed to create a macro. > > (I do a procedure hundreds of times every day so wanted to automate > it) > > I press Control-F (to open the 'find' dialogue) and then press > Control- V (to paste the contents) into the dialogue. As you can see > from the code below, when I recorded the macro, it used '2022' (which > is what happens to be in my clipboard right now) but I want it to use > the clipboard. > > > Is this possible? I hope I've explained the problem properly. > > > > > ==================================================== > > > > > > Sub FindWhatsinClipboard() > ' > ' FindWhatsinClipboard Macro > ' Macro recorded 26/03/2010 by John Smith > ' > Selection.Find.ClearFormatting > With Selection.Find > .Text = "2202" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindAsk > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > Selection.Find.Execute > Selection.Find.ClearFormatting > With Selection.Find > .Text = "2202" > .Replacement.Text = "" > .Forward = True > .Wrap = wdFindAsk > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > End Sub
From: John on 29 Mar 2010 05:48 On Mar 26, 3:12 pm, "Jay Freedman" <jay.freed...(a)verizon.net> wrote: > Hi John, > > Replace the line > > .Text = "2202" > > with > > .Text = Selection.Text > > Also, everything the recorder put into the macro after the line > > Selection.Find.Execute > > is worthless and can be deleted. For enlightenment, seehttp://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm. > > -- > 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. > > > > John wrote: > > Hi > > > I tried, and failed to create a macro. > > > (I do a procedure hundreds of times every day so wanted to automate > > it) > > > I press Control-F (to open the 'find' dialogue) and then press > > Control- V (to paste the contents) into the dialogue. As you can see > > from the code below, when I recorded the macro, it used '2022' (which > > is what happens to be in my clipboard right now) but I want it to use > > the clipboard. > > > Is this possible? I hope I've explained the problem properly. > > > ==================================================== > > > Sub FindWhatsinClipboard() > > ' > > ' FindWhatsinClipboard Macro > > ' Macro recorded 26/03/2010 by John Smith > > ' > > Selection.Find.ClearFormatting > > With Selection.Find > > .Text = "2202" > > .Replacement.Text = "" > > .Forward = True > > .Wrap = wdFindAsk > > .Format = False > > .MatchCase = False > > .MatchWholeWord = False > > .MatchWildcards = False > > .MatchSoundsLike = False > > .MatchAllWordForms = False > > End With > > Selection.Find.Execute > > Selection.Find.ClearFormatting > > With Selection.Find > > .Text = "2202" > > .Replacement.Text = "" > > .Forward = True > > .Wrap = wdFindAsk > > .Format = False > > .MatchCase = False > > .MatchWholeWord = False > > .MatchWildcards = False > > .MatchSoundsLike = False > > .MatchAllWordForms = False > > End With > > End Sub- Hide quoted text - > > - Show quoted text - Thanks very much
From: John on 30 Mar 2010 08:19 On Mar 26, 3:12 pm, "Jay Freedman" <jay.freed...(a)verizon.net> wrote: > Hi John, > > Replace the line > > .Text = "2202" > > with > > .Text = Selection.Text > > Also, everything the recorder put into the macro after the line > > Selection.Find.Execute > > is worthless and can be deleted. For enlightenment, seehttp://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm. To Jay/other clever people, Okay, a TWIST. How can I get it to switch to a DIFFERENT Word document, to search for the specific text (that was in the first Word document) Thanks very much!
From: Graham Mayor on 30 Mar 2010 08:59 "John" <helpme.code(a)yahoo.com> wrote in message news:adf44bb9-616b-4f3f-8c8c-7e611646b53d(a)x12g2000yqx.googlegroups.com... >To Jay/other clever people, >Okay, a TWIST. >How can I get it to switch to a DIFFERENT Word document, to search for >the specific text (that was in the first Word document) > Thanks very much! You would have to address the document in question after storing the selected text in a variable - here sText e.g to follow the code you have already created. Change the information in sPath = to reflect the document that you want to search. Sub FindWhatsinClipboard() Dim sText As String Dim sPath As String sPath = "D:\My Documents\Test\Name1.docx" 'store the selected text sText = Selection.Text 'open the other document Documents.Open sPath 'The opened document is now the active document Selection.Find.ClearFormatting With Selection.Find .Text = sText ' the stored selection .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 -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
|
Pages: 1 Prev: SQLDataAdapter Fill with startRecord parameter Next: translation models |