The VBA Editor - Organizing
- 02:39
Understand how to work with Modules in the VBA Editor
Downloads
No associated resources to download.
Glossary
VBA ModulesTranscript
So, let's have a look at how we can organize our macros by using modules. We've seen that when we record macros, those macros get recorded into one or more modules and these modules have the default names of module one, two, three, four, and so on. Now, obviously, it would make sense for us to be able to give them more useful names so we can remember what macros we put into what modules. So you can think of modules like being, like folders and people use those to organize their macros in lots of different ways. So we might have, for example, all the macros that relate to a particular job I do or maybe all the macros that do formatting or all kinds of different things that people might come up with different modules for their macros. So to rename a module, all we need to do is have it selected in the project window and then in the properties window, we just need to come down and rename the module. Now the module name rules are very similar to the same rules that we saw when we are renaming our macros, so we can't have spaces and those kind of things. So again, a mixture of upper and lower case or the use of underscore characters will help ourselves out here. So, I'm just gonna call this InsertMacros.
Okay. And you can see now I've renamed that module.
We can also insert other modules. So up to the insert menu, module, and you'll see we've got a new module called module one.
I'll just rename that one.
So now, we've got InsertMacros and a new module called NewMacros and we can carry on adding different modules that act like these folders for the storage of macros. Now if I want to transfer one macro from one module to another, that's absolutely fine. All you need to do is go up to the one where you want to copy the macro from, select the entire macro. So, everything from between the word Sub and End Sub. I'm just gonna cut that out. So shortcut control X, go to the window where I want to paste it. So I now wanna put this in the new macros window and control V to paste it in. So you can organize your macros and make things much more structured by creating new modules. And then copying and pasting the recorded macros around from one module to another.