HELP! Object specific Code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Am trying to understand VBA object code. I know that the Modules folders
contain sub routines for that workbook project.

I also noted that you can have code windows open for a particular worksheet.
When I click on the down arrow and select General, this code appears
automatically:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub

What does this mean?
 
Hi Tom,

Thanks for your help! So, I can write code that is stores in the Modules
folder that makes the sub available to all sheets in that workbook only
(unless written in the Modules folder of the Personal folder), OR I can write
code that is specific to only a particular worksheet.

The code is simply stored in the workbook code window; it doesn't have a
container like modules do (being placed in a modules folder)

Are these assumptions correct?

Thanks again!

Tom Ogilvy said:
It is the selectionchange event for that worksheet. It fires whenever the
user selects a cell

http://www.cpearson.com/excel/events.htm
Chip Pearson's page on events (assuming it is back up - seemed to be down
earlier)
 
If you do Insert=>Module you will get an entry under the modules entry in
the project explorer. Code in these modules are available to all code
within that workbook as long as the module is not declared as private or an
individual procedure is declared as private (this is true whether the
workbook is the personal workbook or not -- there is nothing special about
the personal workbook with respect to this).

Each worksheet has a corresponding module. these modules are used to
support sheet level events that can be selected/declared by using the
dropdowns at the top. This code reacts to actions by the user on that
sheet. Performing the action triggers the event code.

Similar there is a workbook level module. In the project explorer it is
shown as the ThisWorkbook module. It supports code for Workbook level
events.

Unless you are writing event code, you should be working in a general
module.

There is a similar situation with a userform. A module is associated with
the userform like a module is associated with a sheet. In fact, these
associated modules are special predefined Class modules.

You may also create you own classes using class modules.

--
Regards,
Tom Ogilvy

dee said:
Hi Tom,

Thanks for your help! So, I can write code that is stores in the Modules
folder that makes the sub available to all sheets in that workbook only
(unless written in the Modules folder of the Personal folder), OR I can write
code that is specific to only a particular worksheet.

The code is simply stored in the workbook code window; it doesn't have a
container like modules do (being placed in a modules folder)

Are these assumptions correct?

Thanks again!
 

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