PDA

View Full Version : Calling Excel shortcuts from VBA



musicgold
05-18-2010, 03:20 PM
Hi,

I am trying to automate the following two excel shortcuts using VBA. I know I can use commandbar and commandcontrol to call excel menus but I can not find the submenus these shortcuts belong to.

1. Ctrl + [ -- cursor goes to the precedent cell
2. F5 + Enter -- cursor goes to the original cell


Also, is it possible to call an excel shortcut from VBA? I know that one can call a worksheet function from VBA (For example, Application.WorksheetFunction.Fact(5) ). But is there way to call a shortcut, say Ctrl + C from VBA?

Thanks,

MG.

Simon Lloyd
05-18-2010, 04:50 PM
You would need to use the SendKeys method but it's not very reliable.

GTO
05-19-2010, 01:56 AM
As Simon noted, to call the actual shortcut key combo, SendKeys. Of course you can duplicate the actions carried out by some of the shortcut key combos; such as your first one:

On Error Resume Next
ActiveCell.DirectPrecedents.Select
On Error GoTo 0

Not sure if that helps?

musicgold
05-20-2010, 05:28 AM
Thanks folks.

GTO,

That command works only for cells within a sheet. Ctrl+ [ works even for links in other workbooks. I don't know if you have any other solution.
Thanks.