Macro code for ALT+release

M

Mark Tangard

<>Hey gang. Is there a programmatic way to simulate the pressing and
releasing of the ALT key, or alternatively, to activate a specified tab
of the ribbon?

Thanks for any clues.

MT
 
D

Doug Robbins - Word MVP

Use

SendKeys "%"
SendKeys "M"

The M in the second line activates the Mailings tab. Replace the M with the
one for the tab that you want to activate.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
M

Mark Tangard

Hm. OK, this works, but I notice I can't then reassign this code to any
ALT+Letter combination. Other hotkey-plus-letter combination work fine,
but ALT+anything seems crippled.

This is perhaps an bizarre/futile quest, but I'm trying to duplicate a
few 2003 custom menu keystrokes for a user who's been thoroughly
traumatized by the ribbon (more traumatized than I was, which was
considerably). So I'm attempting to map a few items now on the Add-Ins
tab (ALT, X, etc) to the combinations she's used to.

In Word 2003 no ALT+Letter shortcuts were ever intercepted or ignored.
Any clues how to make that happen again?

MT
 
M

Mark Tangard

Hi Tony,

That's a pretty neat userform, but I was hoping for more pedestrian code
that simply activates, with certainty, a specific ribbon tab, so that
the next keystroke will run a corresponding command. Do you know of
anything roughly of the form "xTab(name).Activate" that might approach this?

MT
 
T

Tony Jollans

I'm afraid the only 'more pedestrian' code is the Sendkeys that Doug gave
you, with all the attendant problems.
 
M

Mark Tangard

Hi Tony - It's not keystrokes per se, it's assigning a custom hotkey to a
(different-in-2007) series of keystrokes to do what the hotkey used to do. If I
assign any ALT+letter combination to a macro that uses SendKeys, the SendKeys
lines misbehave. For example, say a macro contains:

SendKeys "%"
SendKeys "x"
SendKeys "s"

If this macro is run from the Macro dialog, or from a button assigned to it on
the QAT, or via an assigned hotkey combination that *isn't* of the form
ALT+something, it runs as intended -- that is, it runs the command that bears
the S accelerator on the AddIns tab. But if I assign, say, ALT+D to that macro,
pressing ALT+D just types "xs" (or sometimes just "s") into the active document.

I'm not that freaked out about this & have always wanted to nail SendKeys to the
wall and torture it anyway. It's just strange that ALT+whatever hotkey
combinations seem to fail substantially more often now if assigned to a
SendKey-exploiting macrom

MT.

Tony said:
What keystrokes from 2003 can you not use in 2007?
--
Enjoy,
Tony

www.WordArticles.com

Hm. OK, this works, but I notice I can't then reassign this code to any
ALT+Letter combination. Other hotkey-plus-letter combination work fine, but
ALT+anything seems crippled.
This is perhaps an bizarre/futile quest, but I'm trying to duplicate a few
2003 custom menu keystrokes for a user who's been thoroughly traumatized by the
ribbon (more traumatized than I was, which was considerably). So I'm attempting
to map a few items now on the Add-Ins tab (ALT, X, etc) to the combinations
she's used to.
In Word 2003 no ALT+Letter shortcuts were ever intercepted or ignored. Any
clues how to make that happen again?
releasing of the ALT key, or alternatively, to activate a specified tab of the
ribbon?
 
T

Tony Jollans

Very odd - in some ways classic SendKeys, and I'll quite happily hold the
nails for you!

If you use:

SendKeys "%"
SendKeys "%"
SendKeys "x"
SendKeys "y"

.. it works in response to an Alt+ hotkey, but ... it then doesn't work via
Alt+F8.

From limited testing it seems as if:

SendKeys "%"
SendKeys "{ESC}"
SendKeys "%"
SendKeys "x"
SendKeys "y"

.. works all the time. It appears as though the focus for the "%" is in the
wrong place but just sending ESC wasn't enough. Just don't ask me to explain
any of this!!
 
M

Mark Tangard

Owwww, that truly *is* classic SendKeys, and I never in a million years would've
discerned it. Thanks, Tony, I owe you.

MT
 

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