PDA

View Full Version : Pausing a Macro for User Action



jennyhuf
01-23-2013, 12:52 PM
I've created a simple macro that types in text that is supposed to surround a paragraph. For example, the finished text should look like this with the blue text changing depending on what I'm working on:

[[*ind6*]][[*rm5*]]For a detailed account of how to research this particular product call us at (123) 456-7890.[[*ind0*]][[*rm0*]]

All I want to do is have the macro type in the first part of the text where I've placed the cursor, stop and allow me to move the cursor where the rest of the text goes, and then have the macro start up again to type the rest of the text. For example, right now the macro reads:

Selection.TypeText Text:="[[*ind6*]][[*rm5*]][[*ind0*]][[*rm0*]]"

I want it to stop and let me move the cursor as follows:

Selection.TypeText Text:="[[*ind6*]][[*rm5*]]"
Move cursor
Selection.TypeText Text:="[[*ind0*]][[*rm0*]]"

I don't need an input box...I just need to pause it and then restart it once I move the cursor.

I'm sure this is an easy fix, but I'm not a developer and haven't been able to find a similar situation online.

Frosty
01-23-2013, 01:46 PM
There's no real easy way to do that, actually. Is there a reason why you can't simply create two macros?

Sub Macro1()
Selection.TypeText Text:="[[*ind6*]][[*rm5*]]"
End Sub
Sub Macro2()
Selection.TypeText Text:="[[*ind0*]][[*rm0*]]"
End Sub

What you're really describing would be an event handler that monitors your the changing of you selection-- an endeavor that I suspect really isn't worth it.

And, in fact, even easier than dealing with a macro would be investigating the built-in Autotext/BuildingBlock feature set (depending on the version you're of Word you're working on)

You can define an Autotext entry as a some text (rich text or just plain text), and then give it a unique code (at least 4 characters), and when you begin typing that "code" -- once you get to 4 characters, you can press F3 and the text of the autotext entry will be inserted.

So you could define two autotext entries.

I don't know where you're getting the values in the bracketed text, but I would start reading about Autotext and Building Blocks...

As an additional note-- I would suggest a naming convention for your autotext entries to being with an * character, so that you don't have autotext autocomplete popping up at strange times...
*ind6
*ind0

would be my suggestions for your autotext names, based on what you've posted... try it out.

Paul_Hossler
01-24-2013, 07:22 AM
[[*ind6*]][[*rm5*]]For a detailed account of how to research this particular product call us at (123) 456-7890.[[*ind0*]][[*rm0*]]


What about an approach where you select text (i.e. the blue) with mouse or KB, and then run your macro to insert the [[*ind6*]][[*rm5*]] in front of the Selection, and the [[*ind0*]][[*rm0*]] at the end of the Selection?

Paul