force keyboard (ALT) shortcuts in VBA Code?

S

Steve Mackay

Is it possible to force your vba code to use keyboard shortcuts - like "CTRL
+ C" or "ALT + E + C+ENTER" instead of "Selection.Copy".

The reason why I ask is that I have an add-in menu in Excel located between
the "Data" & "Windows" menus that I would like to access in a macro. The
shortcut would be "ALT +L+A+ENTER

Thanks,
Steve
 
J

Jim Cone

Steve,

The direct answer to your questions is to tell you to look at "SendKeys" in help.
A easier method would be to set a reference to the Add-in in Tools | References in the VBE.
That will allow you to call the macro using the run method...

Application.Run("MacroName")

Regards,
Jim Cone
San Francisco, CA
 
S

Steve Mackay

Thanks for the tip. I understand it in concept but can't seem to get it to
work in practice. So, to go back to my paste example, my code would look
like this?

Sub test()
Application.SendKeys ("%ep")
End Sub

But that doesn't seem to work correctly. Can you give me an example.
Sorry, I know this is probably very basic programming, but I appreciate your
help.

Steve
 
J

Jim Cone

Steve,

If you want to paste then these work...

Application.SendKeys ("%(e)p~") ' I added the enter key

Application.SendKeys ("^(v)") ' or
Application.SendKeys ("^v") ' without the ()

Remember to do this from the spreadsheet, not from the VBE.

Also, note that there are two versions of SendKeys...
omit "Application" to send to the active window.
use "Application" to send to the application.

Experiment a little.

I still recommend Application.Run("Name of Sub")

Regards,
Jim Cone
San Francisco, CA
 
S

Steve Mackay

Thanks,
I'll play with it a bit. I don't understand the last thing you said, but
I'll look into it.

Steve
 

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