How To Create Vba Code Modules In Excel

preview_player
Показать описание

In this video I explain the different places to store macros, functions & VBA code in a workbook. We specifically look at the Code Module, Sheet Module, and ThisWorkbook Module to learn the differences between how each works.

Code Modules allow us to store regular macros (sub procedures) and functions (User Defined Functions, UDFs). This is the typical place we start writing and storing our macros. The macro recorder also creates code in a code module.

Each sheet in the workbook has a sheet object in the VB Editor. These are listed in the Microsoft Excel Objects folder for each open workbook in the Project Window. Double-clicking a sheet object opens its code module. Here we store regular macros & functions.

We can also Event Procedures that will run when the user takes an action in the worksheet. This could be actions like selecting a cell, activating a sheet, or deleting a sheet. There are a lot of events for the sheet object.

Each workbook contains one object called ThisWorkbook. The ThisWorkbook object is stored at the bottom of the Microsoft Excel Objects folder.

The main purpose of the ThisWorkbook module is to run event procedures (macros) when the user takes an action in the workbook. This could be when the user opens the workbook, before they close the workbook, when they select a worksheet, range, or even update a pivot table.

Register for my free training webinar on macros & VBA:
Рекомендации по теме
Комментарии
Автор

Thank you very much. Not having used VBA in Excel for many years, I had forgotten the logic of where to put my code depending on what functionality I wanted. Your accurate, to-the-point description helped me refresh my memory and not waste as much time looking around for solutions to my basic (no pun intended) errors.

EnriqueMedina-xjmg
Автор

I am new and trying to learn VBA. This video helped me a lot to clear my understanding of different modules in VBA. Effectively explained the difference, in Code Module, Sheet Module, and This Workbook Module.Thanks

faizulaziz
Автор

Great, comprehensive explanation. Simply perfect! Thanks!

michalfomaidis
Автор

Jon you're awesome! I am very new to actual 'coding' in excel via VBA / Macros etc. I was really lost about where to place codes and this has been a huge help! Thanks buddy! It's already starting to make way more sense now! :)

mofojackson
Автор

Love hearing new perspectives of other entrepreneurs, keep up the hustle! 🚀

TheMinderEngineer
Автор

This helps a lot, Thank you... Best Regards from Panama City in Central America.

darenj
Автор

Although, I am already enrolled in multiple excel training courses. None of the instructors
bring the clarity that you provide to the subject matter. Thanks for the tutorial. I'm in for the webinar(s).

MrGman
Автор

Hi. I just wanted to tell you that your videos are really amazing.

MrLinox
Автор

Awesome video! Now everything makes sense! Now I know what every section is for! Thanks so much :)

Petero
Автор

Excellent video. I learned so much. Thanks.

ivanshaw
Автор

Thanks. Its Clear and understandable easily,

horilalsoni
Автор

Thanks ... really sensible explanation

TheHughabbott
Автор

2023-03-22 2017Z

Outstanding, Jon; thank you. A beautifully clear presentation, both in enunciation and in video quality.

I don't mean to sound xenophobic but I wish every-one that made such material for the Internet would watch -- and learn from -- your work.

ΠΞ

periclesxanthippou
Автор

Thank you so much~ This gives a really wholesome intro to VBA! Cheers!

cindydu
Автор

hi, do you have continue video which tells about class module and userforms

sabbathdaniel
Автор

V early explained. Thx for the same.👍

ashishtrivedi
Автор

Hi, this is a great video. I have a question. If I have a code in a Module macro, and want to call it from a Sheet Macro (when an event is made), Can that be made possible?

anirbandas
Автор

Well explained. Looking forward to your tutorials on class module code and user form code.

sandeepkothari
Автор

Hi Jon.
I have a question. It is possible to attach a SqLite database in an Excel file, and then use it, but it is inside the file in such a way that it is not visible to the users, maybe it is part of the xml file that is created when the Ribbon is customized of a File in Excel

juancena
Автор

Hi, where is part two of this video? I was wanting to learn about Class Modules.

ApacheGamingUK