<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: How to: Word Macros with User Input?</title>
	<link>http://ask.metafilter.com/156392/How-to-Word-Macros-with-User-Input/</link>
	<description>Comments on Ask MetaFilter post How to: Word Macros with User Input?</description>
	<pubDate>Thu, 10 Jun 2010 16:35:36 -0800</pubDate>
	<lastBuildDate>Thu, 10 Jun 2010 16:35:36 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: How to: Word Macros with User Input?</title>
		<link>http://ask.metafilter.com/156392/How-to-Word-Macros-with-User-Input</link>	
		<description>WordMacroFilter: I&apos;m trying to set up a Word Macro using find and replace but that waits for user input... &lt;br /&gt;&lt;br /&gt; I want to set up some Word Macros (Word 2007 and 2010) that make use of the find and replace, but that don&apos;t do a &apos;blind&apos; replace all.&lt;br&gt;
&lt;br&gt;
So for example, I want to be able to have a macro that does a find and replace for two spaces and replaces it with one... but I don&apos;t want to do a replace all, because sometimes the documents in question have things that are positioned using spaces rather than tables. (yeah, yeah, I know, that&apos;s another issue.) I want the option to be able to say yay or nay to each replace. &lt;br&gt;
&lt;br&gt;
If I record a macro using the find and replace set up, it just quits after one find and replace. Hitting the macro button multiple times really isn&apos;t viable. &lt;br&gt;
&lt;br&gt;
How do I set this up? VB code examples would be great. I&apos;m thinking Loop? I don&apos;t know... &lt;br&gt;
&lt;br&gt;
(I have a number of such find and replace requirements, so I&apos;m looking to save time on the set up of these via macros).</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2010:site.156392</guid>
		<pubDate>Thu, 10 Jun 2010 15:37:19 -0800</pubDate>
		<dc:creator>Zinger</dc:creator>
		
			<category>macros</category>
		
			<category>msword</category>
		
			<category>wordmacros</category>
		
	</item> <item>
		<title>By: gubenuj</title>
		<link>http://ask.metafilter.com/156392/How-to-Word-Macros-with-User-Input#2241727</link>	
		<description>Since no matter what, you want to visually inspect each occurrence, the only way I can think to do this is to set up two macros. The first, let&apos;s call it &quot;Find-next&quot; finds the two spaces, and then moves back to the previous character.  If you want to replace, then you invoke the second, we&apos;ll call &quot;Find and Replace&quot;, finds the one you just found and then replaces it and moves forward a character. If you don&apos;t want to replace, you just invoke your &quot;Find-next&quot; macro twice (because you are at the character before the occurrence) to find the next subsequent occurrence.  If you set up shortcut keys, (e.g. ctrl-6 for Find-next and ctrl-7 for Find and Replace) you can probably pretty quickly move through your document (just as quickly as pressing &quot;y&quot; and &quot;n&quot;) assuming you were able to make a loopy VB code.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2010:site.156392-2241727</guid>
		<pubDate>Thu, 10 Jun 2010 16:35:36 -0800</pubDate>
		<dc:creator>gubenuj</dc:creator>
	</item><item>
		<title>By: NailsTheCat</title>
		<link>http://ask.metafilter.com/156392/How-to-Word-Macros-with-User-Input#2241753</link>	
		<description>You could try something like below. It&apos;s a bit icky using SendKeys but it will work.&lt;br&gt;
&lt;br&gt;
&lt;code&gt;&lt;br&gt;
Sub FindAndReplaceSpaces()&lt;br&gt;
    FindAndReplace &quot;  &quot;, &quot; &quot;&lt;br&gt;
End Sub&lt;br&gt;
&lt;br&gt;
Sub FindAndReplace(strToFind As String, strToReplaceWith As String)&lt;br&gt;
frmSelect.Show (vbModal)&lt;br&gt;
&lt;br&gt;
Dim rtn As Variant&lt;br&gt;
&lt;br&gt;
    With Dialogs(wdDialogEditReplace)&lt;br&gt;
        SendKeys strToFind&lt;br&gt;
        SendKeys &quot;{tab}&quot;&lt;br&gt;
        SendKeys strToReplaceWith&lt;br&gt;
        SendKeys &quot;%r&quot;&lt;br&gt;
        SendKeys &quot;%r&quot;&lt;br&gt;
        rtn = .Display&lt;br&gt;
    End With&lt;br&gt;
End Sub&lt;br&gt;
&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
I&apos;ve done it as separate procedures so that you can reuse the main procedure for different string combinations. &lt;br&gt;
&lt;br&gt;
Otherwise I would look at creating your own form, displaying that and navigating through the document using that. If you take that approach you could opening up the form modelessly (Form1.Show vbModeless) so you could still scroll up and down if you wanted to on the active document.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2010:site.156392-2241753</guid>
		<pubDate>Thu, 10 Jun 2010 16:58:10 -0800</pubDate>
		<dc:creator>NailsTheCat</dc:creator>
	</item><item>
		<title>By: NailsTheCat</title>
		<link>http://ask.metafilter.com/156392/How-to-Word-Macros-with-User-Input#2241759</link>	
		<description>Oops. Remove that line &quot;frmSelect.Show (vbModal)&quot;. That was just me checking the constants for modal / modeless.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2010:site.156392-2241759</guid>
		<pubDate>Thu, 10 Jun 2010 17:04:03 -0800</pubDate>
		<dc:creator>NailsTheCat</dc:creator>
	</item><item>
		<title>By: Simon Barclay</title>
		<link>http://ask.metafilter.com/156392/How-to-Word-Macros-with-User-Input#2241789</link>	
		<description>What you want is to put your search &amp;amp; replace in an endless loop, and have it break (using &quot;Exit Do&quot;) when (a) there is nothing found, or (b) the user says so. To get the user&apos;s feedback, use the MsgBox function, which shows a Windows-standard message box.&lt;br&gt;
&lt;br&gt;
In your Visual Basic (Alt-F11 to open) search for help on MsgBox. Basically, in the loop you want something like:&lt;br&gt;
&lt;pre&gt;&lt;br&gt;
     Do&lt;br&gt;
 &lt;br&gt;
         &apos;... insert search here...&lt;br&gt;
         &apos;... add code so that if string isn&apos;t found, then exit do or exit sub&lt;br&gt;
 &lt;br&gt;
        Select Case MsgBox(&quot;Do you want to replace this occurrence?&quot;, _&lt;br&gt;
            vbYesNoCancel+vbInformation,&quot;Search/Replace&quot;)&lt;br&gt;
            &lt;br&gt;
        Case vbYes:&lt;br&gt;
            &apos;...insert code to replace...&lt;br&gt;
 &lt;br&gt;
        Case vbNo:&lt;br&gt;
            &apos; keep this empty&lt;br&gt;
 &lt;br&gt;
        Case vbCancel:&lt;br&gt;
            Exit Do    &apos; or use Exit Sub instead, if that&apos;s better&lt;br&gt;
 &lt;br&gt;
    Loop&lt;br&gt;
&lt;/pre&gt;&lt;br&gt;
&lt;br&gt;
I haven&apos;t tried this out, but that&apos;s the basic structure you&apos;re looking for (I think).</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2010:site.156392-2241789</guid>
		<pubDate>Thu, 10 Jun 2010 17:26:08 -0800</pubDate>
		<dc:creator>Simon Barclay</dc:creator>
	</item>
	</channel>
</rss>
