Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default different places to put excel code?

hi there,

could someone tell me the difference between putting a sub in a
worksheet specific code module and a general module?

When I hope my spreadsheet, then do alt-f11, I see Sheet1 with a place
for code, as well as a Module1 that takes code. Sometimes I find that
if I am trying to call a procedure from within Sheet1 code, it won't
find it unless I put the called procedure in the Module1.

I know this must be very basic stuff for Excel. A brief explanation
would be appreciated!

Thanks
Ross
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default different places to put excel code?

I'll try.
sheet specific macros such as worksheet_change must be in the sheet module.
UDF (User defined functions) must be in a regular MODULE
workbook_open and others must be in the ThisWorkbook module
Regular old macros can often be anywhere as long as properly referenced.
HTH
--
Don Guillett
SalesAid Software
Granite Shoals, TX

"Ross" wrote in message
om...
hi there,

could someone tell me the difference between putting a sub in a
worksheet specific code module and a general module?

When I hope my spreadsheet, then do alt-f11, I see Sheet1 with a place
for code, as well as a Module1 that takes code. Sometimes I find that
if I am trying to call a procedure from within Sheet1 code, it won't
find it unless I put the called procedure in the Module1.

I know this must be very basic stuff for Excel. A brief explanation
would be appreciated!

Thanks
Ross



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default different places to put excel code?


"Ross" wrote in message
om...
hi there,

could someone tell me the difference between putting a sub in a
worksheet specific code module and a general module?

When I hope my spreadsheet, then do alt-f11, I see Sheet1 with a place
for code, as well as a Module1 that takes code. Sometimes I find that
if I am trying to call a procedure from within Sheet1 code, it won't
find it unless I put the called procedure in the Module1.

I know this must be very basic stuff for Excel. A brief explanation
would be appreciated!

Thanks
Ross


There are 5 type of location you can put your VBA Code

1) A worksheet (sheet1, sheet2 etc)

This location is where code should be placed that traps one of the
worksheet events (Activate, BeforeDoubleClick, BeforeRightClick etc)
or that traps events of an object owned by the worksheet such as
a ComboBox or RadioButton

2) The ThisWorkbook object

This location is where code should be placed that traps one of the
workbook events (SheetActivate, SheetBeforeDoubleClick,
SheetBeforeRightClick etc)

3) UserForms - Userforms are what you use to define your user interface
and any code specific to that interface such as all the TextBox , ComboBox,
ListBox events shoud go here. You may also add code routines
that are called by that form only

4) Modules - This is the place to put most of your general purpose
program procedures. Basically the rule should be that if you want
call a routine from other places in the Project the procedure
should go into a module.

As your programs get more complex you'll find it valuable to
have some standard modules that you can load into each new
project

5) Class Modules

This is where you put code when you want to declare and
use new object types. Like Excel Objects your types
can have properties and methods , which are defined
in the classmodule and then instantiated and used from
a userform or code module

I suspect this is a little beyond your scope at present

Keith


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default different places to put excel code?

Classes
Class module

Event Related Code (except classes)
Workbook level events : ThisWorkbook module
Sheet level events: Sheet module associated with the sheet
ActiveX Controls on Sheets events: Sheet module associated with the sheet
they are on
Userform/controls on userforms: Userform module
Forms Toolbar controls: General Module
Commandbar OnAction Macros: General Module

Everything else should go in a general module
including user defined functions to be used in a worksheet.

http://groups.google.com/groups?selm...&output=gplain


http://groups.google.com/groups?selm...&output=gplain

http://groups.google.com/groups?selm...&output=gplain

--
Regards,
Tom Ogilvy


"Ross" wrote in message
om...
hi there,

could someone tell me the difference between putting a sub in a
worksheet specific code module and a general module?

When I hope my spreadsheet, then do alt-f11, I see Sheet1 with a place
for code, as well as a Module1 that takes code. Sometimes I find that
if I am trying to call a procedure from within Sheet1 code, it won't
find it unless I put the called procedure in the Module1.

I know this must be very basic stuff for Excel. A brief explanation
would be appreciated!

Thanks
Ross



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fixed decimal places in Excel Garben Excel Discussion (Misc queries) 4 December 9th 08 10:49 PM
My Places bar disappeared in Excel 2003 Olivier[_2_] Excel Discussion (Misc queries) 0 March 6th 08 10:24 AM
VBA code stopping in odd places JDub Setting up and Configuration of Excel 2 October 10th 06 08:04 AM
Excel adds phantom decimal places: why? Dave O Excel Discussion (Misc queries) 1 August 16th 05 06:25 PM
Decimal places in Excel 2003 EXCELNCBOY Excel Worksheet Functions 6 November 5th 04 04:39 PM


All times are GMT +1. The time now is 10:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"