ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Calling Excel shortcuts from VBA (https://www.excelbanter.com/excel-programming/442698-calling-excel-shortcuts-vba.html)

musicgold via OfficeKB.com

Calling Excel shortcuts from VBA
 
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


JLGWhiz[_2_]

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




musicgold via OfficeKB.com

Calling Excel shortcuts from VBA
 
JLGWhiz,

Thanks. I know basic fundamentals related to macros in Excel.

The shortcuts I mentioned in my original message are Excel shorcuts. I am not
able to find the functions underlying them. I want to be able to execute
those shortcuts inside a macro.

MG.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/201005/1



All times are GMT +1. The time now is 09:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com