Where Macros Are Located

G

George B

I've noticed in VBE that there are a number of locations where macros may be
created and executed:

1. Each sheet can contain macros
2. There is something called ThisWorkbook
3. There can be a number of modules

Does it make any difference where I put my code?
 
B

Bob Umlas

Absolutely, it does. You also left out Userforms, and class modules.
Most macros are written in modules.
Event-driven macros (like selecting a cell, or closing a workbook) are
written either in the sheet or workbook, depending on the event. Workbooks
have their specific set of events which are separate events from the
workbook (thisworkbook) events.
If you place your macros in a place they don't belong, they either won't
run, or will produce unexpected results.
 
Top