Results 1 to 2 of 2
Thread: Use Keyboard shortcut in macro?
2012-06-13, 08:50 #1
- Join Date
- Dec 2005
- Thanked 0 Times in 0 Posts
Use Keyboard shortcut in macro?
I had a really annoying problem, which I've kind of solved, but was wondering if it could be done more elegantly or simply. since it is about as non-intuitive as you can get at the moment. What I was trying to do was to emulate the pressing of one of the buttons on the ribbon in Excel 2010 from a macro. Eventually I ended up with this
Const cIncreaseDecimal = 398
which is from "old" Excel (pre 2003), but works in 2010. However, while researching this I thought it would be much easier and wouldn't require me finding the "ID" of the command, if I could call a keyboard shortcut from within a macro. Then I could assign whatever shortcut I wanted to whatever button I wanted, then just call that KB shortcut from in the macro. I know the opposite is possible (ie calling a macro from a KB shortcut), but is it possible to do this?
I initially tried recording a macro of the button press and using that ,which usually works fine, but the code for the button seems to read the current number of decimals and then it just runs this when I increased the number of decimals, so some of the code is actually missing!!
Selection.NumberFormat = "0.0000" (my original number had 3 decimal places).
Anyway, if anyone knows a way to run a keyboard shortcut in a macro, I'd really like to know.
2012-06-13, 09:31 #2
- Join Date
- Dec 2000
- Burwash, East Sussex, United Kingdom
- Thanked 116 Times in 111 Posts
Using the commandbars is better than Sendkeys which is what you would need to simulate a keyboard shortcut. (for 2010 you can use application.CommandBars.ExecuteMso "DecimalsIncrease")Regards,
Microsoft MVP - Excel.