View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz[_2_] JLGWhiz[_2_] is offline
external usenet poster
 
Posts: 1,565
Default Calling Excel shortcuts from VBA

VBA is pretty straight forward in moving the cursor to cells.

Range("C5").Select

The above VBA command puts the cursor in cell C5. You can also use the GoTo
method to move the cursor to specific cells.

As for the precedent and original cells. You have to define these cells in
code with a variable.

myPcell = ActiveCell
myPcell.Select

myPcell variable will hold the address of that ActiveCell, no matter which
other cells become the active cell thereafter. So when you select myPcell,
it will return to that original active cell.

Shortcut keys are usually assigned to functions and procedures (macros) that
a user needs to call periodically to perform a specific action in a
worksheet. These procedures have a title line with a name that appears in
the dialog box which can be displayed by clicking Tools Macro Macros in
Excel. There is more than one way to call them from VBA.

1. Just the Name
macro1
This can be used if there is no argumentr to be passed to the
procedure.

2. Using Call
Call macro1
When Call is used when passing arguments to be enclosed in parentheses.
If you use
the key word Call, then you must use the parentheses, even if there are
no arguments.

3. Using Run
Application.Run("<path!macro1", <arg)
This method allows you to run a macro from another workbook.

These are all explained in more detail in the VBA help files. Just type in
keyword Call or Run to view the topic list, then select the topic from the
list.






"musicgold via OfficeKB.com" <u40543@uwe wrote in message
news:a84938e907762@uwe...
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.

--
Message posted via http://www.officekb.com