Where Macros Are Located

  • Thread starter Thread starter George B
  • Start date Start date
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?
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top