Macro execution by Autotext entry

P

Peter

Hello,

Is there any way to get an autotext entry to execute a macro? In other
words, I'd like to create an autotext entry that when the user gets the
pop-up to press enter, that when they do, it executes a macro. I'm pretty
sure there is no way to do this but I just thought I'd ask to be sure. I'm
using Office 2003 but 2007 available.

Thanks,
Peter
 
J

Jay Freedman

Peter said:
Hello,

Is there any way to get an autotext entry to execute a macro? In other
words, I'd like to create an autotext entry that when the user gets
the pop-up to press enter, that when they do, it executes a macro.
I'm pretty sure there is no way to do this but I just thought I'd ask
to be sure. I'm using Office 2003 but 2007 available.

Thanks,
Peter

You're right, that isn't going to work.

I think the closest you'll get is to include a MacroButton field in the
autotext result, which the user can click after the entry is inserted to run
the macro.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
J

Jonathan West

Peter said:
Hello,

Is there any way to get an autotext entry to execute a macro? In other
words, I'd like to create an autotext entry that when the user gets the
pop-up to press enter, that when they do, it executes a macro. I'm pretty
sure there is no way to do this but I just thought I'd ask to be sure. I'm
using Office 2003 but 2007 available.

It is possible to assign Enter as a shortcut key to a macro. You can't do it
through the Tools customize dialog, but you can do it in VBA using the
KeyBindings collection.

So, what you can do is have the macro insert the autotext entry and then do
whatever code you want after that.

However, if you are going to do this, you need to be VERY careful how you
write the macro, since it will be run every time you press Enter whether or
not the AutoComplete tooltip is showing, which means you have to get the
macro to do everything Word normally does when you press Enter. There are a
surprisingly large number of conditions that need to be addressed.

This isn't impossible, but it is a tough task. Unless you really feel you
must go this route, I would recommend you make inserting the AutoText and
running the subsequent macro as two separate actions.
 
F

fumei via OfficeKB.com

An excellent response Jonathan.

Just to add my voice. AutoText entries are not, in themselves, executable.
They are the results of an action (inserting them), not actions themselves.
Yes, you could put a MACROBUTTON into one, so the user could execute
something with that. But inserting an AutoText itself will not execute
anything.

Yes, you can do things with the Enter key, but I would concur with Jonathan
that doing this requires careful thought and consideration.

Why not go another route? One macro that inserts the AutoText, then does
whatever else.

Jonathan said:
[quoted text clipped - 3 lines]
sure there is no way to do this but I just thought I'd ask to be sure. I'm
using Office 2003 but 2007 available.

It is possible to assign Enter as a shortcut key to a macro. You can't do it
through the Tools customize dialog, but you can do it in VBA using the
KeyBindings collection.

So, what you can do is have the macro insert the autotext entry and then do
whatever code you want after that.

However, if you are going to do this, you need to be VERY careful how you
write the macro, since it will be run every time you press Enter whether or
not the AutoComplete tooltip is showing, which means you have to get the
macro to do everything Word normally does when you press Enter. There are a
surprisingly large number of conditions that need to be addressed.

This isn't impossible, but it is a tough task. Unless you really feel you
must go this route, I would recommend you make inserting the AutoText and
running the subsequent macro as two separate actions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top