ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to use: ThisWorkbook module (https://www.excelbanter.com/excel-programming/314063-how-use-thisworkbook-module.html)

RichardG

How to use: ThisWorkbook module
 
Greetings All,

In doing a word search on "ThisWorkbook" in this newsgroup's archives,
there was a lot of discussion on what to put into this module. What I
wanted to know is, what is the advantage of using this module verses a
general module or the worksheet module; and what is the purpose for
this module?

Many thanks in advance.

RichardG

Jake Marx[_3_]

How to use: ThisWorkbook module
 
Hi RichardG,

RichardG wrote:
In doing a word search on "ThisWorkbook" in this newsgroup's archives,
there was a lot of discussion on what to put into this module. What I
wanted to know is, what is the advantage of using this module verses a
general module or the worksheet module; and what is the purpose for
this module?


The ThisWorkbook module is a class module that contains the events
subroutines that are raised due to certain Workbook-related events. For
example, the Workbook_Open event routine will be executed when the Workbook
is opened. The Workbook_SheetActivate event routine will be executed when
the user (or code) activates a new Worksheet within the Workbook.

So, code related to the Workbook events should be placed in the ThisWorkbook
module. The various Worksheet modules are used for Worksheet-related events
(such as Change and SelectionChange), and standard modules should be used
for your VBA functions and subroutines.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


RichardG

How to use: ThisWorkbook module
 
Thanks Jake,

Your explanation has been most helpful.

RichardG

"Jake Marx" wrote in message ...
Hi RichardG,

RichardG wrote:
In doing a word search on "ThisWorkbook" in this newsgroup's archives,
there was a lot of discussion on what to put into this module. What I
wanted to know is, what is the advantage of using this module verses a
general module or the worksheet module; and what is the purpose for
this module?


The ThisWorkbook module is a class module that contains the events
subroutines that are raised due to certain Workbook-related events. For
example, the Workbook_Open event routine will be executed when the Workbook
is opened. The Workbook_SheetActivate event routine will be executed when
the user (or code) activates a new Worksheet within the Workbook.

So, code related to the Workbook events should be placed in the ThisWorkbook
module. The various Worksheet modules are used for Worksheet-related events
(such as Change and SelectionChange), and standard modules should be used
for your VBA functions and subroutines.



All times are GMT +1. The time now is 11:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com