Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where to write code for VBA?

Status
Not open for further replies.

KC78

Technical User
Mar 17, 2004
16
US
Hello,

Just as a clarification for best practice, can someone tell me........?

Say, I open Excel. I have Book1. I go into VB Editor, and I see in the project tree that I have VBAProject(Book1). And if I open another new Worksheet, I get VBAProject(Book2). Then under VBAProject, the tree breaks into "Microsoft Excel Objects", which then further breaks down into "Sheet1", "Sheet2"......"This Workbook".

My question is, I have an option of inserting a "MODULE", "CLASS MODULE" and "USER FORM". When I write code, what should be put in where??????? for the sake of better code organization etc........????

I used to put everything into "This Workbook", but then it becomes a whole page of procedures.........

I'm only using Excel as an example, but I do alot of other VBA stuff for Engineering Applications. Can someone please clarify the ussage of modules, objects, etc.....???

Regards,
Kenny
 
Hi,

I'd put you code in Modules.

Then there are Worksheet or Workbook event-related stuff. That code goes in the sheet/book object respectively.

:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
As SkipVought said modules are the place to put most of your code.

And if you are trying to create a user defined function then it NEEDS to be there.

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top