Associate macro with Style

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way of associating a macro with a particular style? The objective
is for the macro to run on the application of the style; the macro does such
things as create an index entry, conditionally shade particular lines etc.
 
You'll get better answers about macros if you ask in a newsgroup with VBA or
Programming (plus Word) in the name.

However, it sounds to me as though some process would have to constantly be
checking whether a style had been applied to trigger the macro, and that
sounds difficult and inefficient.

Why not use a macro to apply the style instead? I.e., select text, call the
macro, and it applies the style to selected text, and then does everything
else you want.

Note: It is possible to intercept Word's built-in commands. I.e., if you
name a macro FilePrint, whenever someone clicks Print and calls the
FilePrint command, your FilePrint macro will intercept it and run instead.
(I may have the exact wording off there, but that's the concept). I have
not a clue whether Styles can be intercepted like that. You can ask in the
VBA group.
 
Thanks Daiya.

I can run a macro to apply the style although it is not as intuitive as
having the application of the style automatically running the macro.

I might resort to creatng a toolbar with a button for the macro: that might
be intuitive enough!
 
Well, ask in a VBA group if you can intercept Styles.

Do other people have to use this? If you created a custom style menu or
toolbar with only the styles they were supposed to use, then you could
switch in your macro and no one would be the wiser. But anybody who uses
keyboard shortcuts would be annoyed.
 
The Style command, as other commands that take arguments (like the style
name in this case) can't be intercepted as far as I know.

There are a handful of built-in commands that apply certain styles
(NormalStyle, ApplyHeading1 ... ApplyHeading3, ApplyListBullet) that can be
intercepted, but Word doesn't run these commands if you assign those styles
from the style dropdown or from the task pane.

The "styles and formatting" task pane is more or less inaccessible to VBA,
so there's really no practical way to do your own stuff if a user applies
some style... unfortunately.
I might resort to creatng a toolbar with a button for the macro:
that might be intuitive enough!

Yes, and hope for the best that users will use it, instead of applying the
style in some other way.
If they are used to the task pane, that might prove difficult.

It's a shame that Word got harder and harder to automate in recent versions.
The task pane just made things worse.

:-( Klaus
 

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

Back
Top