Locked lesson.
About this lesson
How to run a macro from a keyboard shortcut.
Exercise files
Download this lesson’s related exercise files.
Keyboard shortcuts - Start.xlsm22.4 KB Keyboard shortcuts - Complete.xlsm
23.5 KB
Quick reference
Running Macros: Using keyboard shortcuts
Creating and managing keyboard shortcuts for your macros.
When to use
When you want to give your users an easy way to run a macro.
Instructions
Creating Shortcut
- Open the macro dialog box and go into Options.
- Enter the key you want to use for the shortcut.
- Test your shortcut before adding it to the macro so that you do not overwrite a pre-programmed shortcut.
Managing Shortcuts
- Open the macro dialog box and go into Options.
- Update the shortcut as required
Hints & tips
- To add SHFT to the shortcut, hold down SHFT and then the key to use.
- While the shortcut key gets written into the macro comments upon creation, it is never updated. It is a good idea to keep the comments up to date if you update the keyboard shortcut.
- 00:05 Now, this time I'd like to come up with a different way of running my Macro.
- 00:09 The last thing I want to do is send a user if I am developing this file for
- 00:13 them into this little dialog box up here, every single time.
- 00:18 This is kind of freaky, nobody wants to be looking at this particular piece, right?
- 00:22 So, it would be nice if we could do something different and
- 00:24 give them a different way to actually run this file.
- 00:27 Well, as it happens, when you come in here, you can go to Options.
- 00:31 And inside options, you have the ability to setup a shortcut key.
- 00:35 You'll also notice the description, the Macro support.
- 00:38 This is what I typed originally when I originally recorded this macro.
- 00:43 This is also the same thing that shows up down at the bottom.
- 00:47 Now if I wanted to be helpful here, I could go in and say, you know what,
- 00:51 why don't I go and say run this macro by pressing
- 00:57 Control plus Shift +R, there we go.
- 01:04 Hold on, let me just make this a little bit nicer and tidier.
- 01:08 There we go.
- 01:09 So at this particular case, if I were to say OK,
- 01:12 I haven't assigned a keyboard shortcut.
- 01:13 But you'll notice that it changes the description that's showing down at
- 01:16 the bottom here.
- 01:17 So this is kinda nice cuz it's A little bit helpful if somebody does
- 01:19 pop into this.
- 01:20 Or in future, if I forget the keyboard shortcut that I've set up, I can go
- 01:25 on somebody else's workbook even if they don't have the Developer tab showing and
- 01:29 I can say.
- 01:32 It'll pop up the Macro dialog and
- 01:33 we can see that I actually have it in the description.
- 01:36 Of course, if I'm like most programmers I'm kinda lazy and
- 01:40 don't bother filling that in.
- 01:42 So at that point the only way to figure out what's going on in here, what
- 01:45 the keyboard shortcut would be, would be to highlight the macro and press options.
- 01:49 So I'll prepare you for both scenarios here because chances are you're going to
- 01:52 run into both of those things.
- 01:54 You're gonna run into somebody who was lazy and
- 01:55 didn't bother filling in the documentation.
- 01:57 You'll run into somebody who filled in the documentation but
- 02:00 then changed it afterwards.
- 02:01 The documentation is wrong.
- 02:03 And you'll run into something where the documentation is correct.
- 02:06 The problem is its always one of these things, trust but verify.
- 02:08 You need to be able to know where do we set this thing eventually.
- 02:12 So where we set it and modify it is in the shortcut key over here.
- 02:17 Now the big key part that I want you to recognize here,
- 02:20 if I wanna go with Ctrl Shift R, if I just type in R right now, in case we control R.
- 02:25 Now I don't actually know what a keyboard shortcut does and this is certainly what
- 02:28 we should talk about really briefly here is before you actually go and
- 02:33 work with one of this keyboards shortcuts it's a really good idea to go back and
- 02:38 actually test it first.
- 02:41 So if I go to sell and press control R It does something.
- 02:44 I don't know what it is, but I don't like it and I'm not real happy with that so
- 02:47 I'm going to undo that one.
- 02:49 Control Shift R, if I go and press on it doesn't seem to do anything.
- 02:54 So that's a safe keyboard shortcut to work with.
- 02:57 You always want to test your keyboard shortcut before you assign it otherwise
- 03:01 you're going to find that you've over write key functionality in a program for
- 03:04 example if you were to go and
- 03:06 put in P, instead of printing every time you hit control P it would run your macro.
- 03:12 Now it might be a useful way to actually block certain functionality from happening
- 03:16 although there is other ways to get around those bigger problems like taking a screen
- 03:20 shot or something like even if you disable printing.
- 03:22 But the key part here is that whatever you put in here, test it first or
- 03:26 else you may find out that you're overriding functionality in the program.
- 03:31 If it's something that you never use, that's fine, but
- 03:34 it may be a shortcut that somebody else uses.
- 03:37 And if you send them your solution they'll be very unhappy with you if you've
- 03:40 hijacked their user interface.
- 03:41 So you want to try and avoid that.
- 03:43 I would also say that this is a great opportunity to learn key
- 03:46 Keyboard shortcuts.
- 03:46 And I can tell you that that's actually how I learned a few different ones.
- 03:49 I was like okay, I didn't know that keyboard shortcut did that.
- 03:52 I guess I better not overwrite it, I just might try and use that in my work.
- 03:55 So how do I get to the control shift R?
- 03:58 That's the next question.
- 03:59 I'm going to hold down my shift key and I'm going to type R, and
- 04:02 it puts in the Ctrl+Shift+R.
- 04:05 Fantastic, let's go see if it works.
- 04:07 So we'll say OK, let it cancel, and we'll hope that it works.
- 04:11 Cuz cancel is usually one of those loaded terms, so
- 04:13 that's why I'm gonna get rid of it.
- 04:15 At this point I'm gonna press Ctrl+Shift R.
- 04:18 And you'll notice that it wiped things out.
- 04:21 It rolled forward my balances.
- 04:22 It looks like it's saved it with a new month end.
- 04:24 Let's try this again.
- 04:25 We're going to go down to usage, four thousand, and fifteen hundred,
- 04:29 just like we did before.
- 04:30 I'm going to press control shift R, and
- 04:33 as soon as I do we should see these balances show up over on the beginning And
- 04:37 we should see ourselves go to Ctrl + shift + R.
- 04:42 Beautiful.
- 04:42 It looks like it's working nicely and
- 04:44 if I go back into the screen I can see that I have left myself good notes and
- 04:50 in the option side here's where the shortcut is set up.
- 04:53 So everything looks like it's working very nicely and
- 04:55 I now know where to change it if I need to as well.
Lesson notes are only available for subscribers.