PDA

View Full Version : Solved: coding for specific key strokes



Brett Desper
05-05-2010, 07:18 AM
Once again the newbie needs some help. This is probably also very simple, but I am not finding a way that works in any of the reference stuff I currently have. I need a macro that will execute the following key strokes in word.

alt-x, y, a


Any help is greatly appreciated.

Brett

fumei
05-05-2010, 09:56 AM
Alt-x, y, a sounds....like a macro (procedure). So you want to make another procedure to execute another procedure? Just call that procedure by name.

In other words, WHY do you want to send those key strokes. BTW: VBA does not execute key strokes. It is th eother way around. Key strokes execute things.

That being said, yes, you CAN have VBA "type" keys. Look up SendKeys.

But I suspect you may be going about this incorrectly. Perhaps tell us what you are trying to do?

Brett Desper
05-05-2010, 10:21 AM
alt-x will select the add ins tab on the ribbon in Word 2007. the y will select the proper menu, and the a will give the proper selection from that menu. This would act similar to alt-f, s which would save a document.

To summarize, I am trying to select the addins tab in the 2007 ribbon, select ACT as the menu item, and select one possibility from that menu.

I have tried to record this with no success.

fumei
05-05-2010, 11:35 AM
I do not use 2007 (I hate it). However, the principle is still the same. Keyboard shortcuts point to a procedure. For example (NOT 2007):

Alt-e, a, f

clears the format from the Selection

So does:
Selection.ClearFormatting
The are equivalent. In fact, you could write a NEW macro (procedure) using a NEW, shorter, keyboard shortcut.
Sub MyClearFormat()
' uses Alt-q
Selection.ClearFormatting
End Sub
In which case:

Alt-e,a,f

and Alt-q

now do EXACTLY the same thing. Just like (using your example):

alt-f, s
ctrl-s

do EXACTLY the same thing.

So. Again, I do not use 2007. I am not surprised you can not record a macro to do this. What you need to find out is what procedure is actioned by alt-x,y,a - there has to be one - simply attach a new shortcut to it.


I need a macro that will execute the following key strokes in word.

alt-x, y, a
What you need is a way to execute whatever alt-x,y,a does, not duplicate the keystrokes.

Is this a standard kind of add-in? What add-in? Perhaps someone here knows what is actioned by a specific menu item under ACT (whatever that is).

But if you insist on sending keystrokes, again...look up SendKeys. That is the way VBA sends keystrokes.

Brett Desper
05-05-2010, 12:59 PM
I am not tied to sending keys. I will try to figure out what is function is being called by that. Act premium is a software package (by Sage) that is essentially a giant marketing database for keeping track of customers, sales, quotes, emails, word docs, etc.

fumei
05-05-2010, 01:08 PM
OK. Now is this a true add-in via a .DOT file? If so, you may be able to edit it - or at least find out what the procedure is, the one fired by alt-x,y,a.

However, as this appears to be a commercial product it may very be that you can not get into the .DOT file.

RonMcK3
05-05-2010, 01:32 PM
Brett,

A suggestion. Record a Macro that does what you want to be able to code, then, look at the code VBA created and you'll see what you need to have.

I have Word 2008 on this Mac, so, I'll try to emulate what I'm suggesting that you do; this will help you discover the code you need to have to accomplish what you are asking.

First, I open the Macro Recorder: Tools > Macro > Record New Macro
Then, since I want to run this from a shortcut key, I click the button the Record Macro dialog to Assign macro to Keyboard
On the Customize Keyboard dialog, I click in the text box for Press new shortcut key and I press <control> and T, and then I click the Assign Button, and then I click the OK button
Then, I select the commands that do what I want to automate
I click Format > Tabs...
On the Tabs dialog box, I enter 5.5" and click the Set button to establish a tab stop, then, I click the OK button.
Since I'm done recording, I click Tools > Macros > Stop Recording
Next I look at my macro: Tools > Macro > Visual Basic Editor (aka VBE)
If I need to I click on Normal, expand Modules under it and click on New Macros.

Next, to test my macro, I choose Format > Tabs and Clear All.

Then, I press ctl-T while I'm in a Word Document and voila the tab appears at 5.5".

Here is the code I recorded:
Sub Macro10()
'
' Macro10 Macro
' Macro recorded 5/5/10 by Harcourt
'
Selection.ParagraphFormat.TabStops.ClearAll
ActiveDocument.DefaultTabStop = InchesToPoints(0.5)
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(5.5), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
End Sub
This gives you the code you need to add to another project's module to set tab stops

fumei
05-05-2010, 01:41 PM
Ron...
Brett,

A suggestion. Record a Macro that does what you want to be able to code, then, look at the code VBA created and you'll see what you need to have.
He has already tried that. That is actually the problem.

To summarize, I am trying to select the addins tab in the 2007 ribbon, select ACT as the menu item, and select one possibility from that menu.

I have tried to record this with no success.Unfortunately, even in versions prior to 2007 some actions are NOT recordable. Particularly actions coming from mouse events, like a right click. Although you can get around most of those limitations by using Shift-F10, the standard keyboard shortcut to the right click event. This does work when recording macros.

Brett Desper
05-05-2010, 02:30 PM
I am talking about a different type of tab as well. Yours is a formatting tab; mine is a tab that is connected to the ribbon and is more of a menu style item. More like the tabs at the top of a browser.

macropod
05-06-2010, 02:57 AM
I have Word 2008 on this Mac...

First, I open the Macro Recorder: Tools > Macro > Record New Macro
Somehow I don't think so - Mac Word 2008 has no macro support!

Brett Desper
05-06-2010, 06:59 AM
Well, now I have pretty much decided to use sendkeys. How does the wait function work?

Brett Desper
05-06-2010, 07:10 AM
I have solved this one for now. I needed to set my last wait command to false and it all worked. Thanks for the help.

fumei
05-07-2010, 09:08 AM
Post your (solved) code please.

Brett Desper
05-07-2010, 10:39 AM
The code was just using sendkeys

sendkeys "%", true
sendkeys "character for the tab on the ribbon you want to select", true
sendkeys "character for menu item you want", false
That pretty much took care of it.

Thanks again