Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default Just wondering

G'day there One and All,

I have a workbook with 4 worksheets. In a general code module I've
declared 4 Public variables thusly:

Public aSht as Worksheet
Public sSht... etc.

In my code I then use Set to assign each worksheet to its
variable.

Set aSht = Worksheets("Analysis")

This works fine, however I've found that since I have no control
over which section of the code will run first (determined by the user's
options) I've had to assign the variables more than once, at the start
of several different routines.

Is there anywhere I can put the assignments where I need only use
them once?

I thought of the Workbook_Open() section of ThisWorkbook, but
that's not going to work as it runs before the sheets are loaded.

Any ideas? It's not a biggy, as my code runs successfully and this
may just have to be. I just thought there may be a more elegant &
efficient way to assign them.

See ya
Ken McLennan
Qld, Australia
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Just wondering

In a general module, not the thisworkbook module, put in your public
variables

then in the ThisworkbookModule

Private Sub workbook_open()

set aSht = thisworkbook.Worksheets("Sheet1")
set sSht = Thisworkbook.Worksheets("Sheet2")
etc.

end Sub

It should work.

--
Regards,
Tom Ogilvy


"Ken McLennan" wrote in message
.. .
G'day there One and All,

I have a workbook with 4 worksheets. In a general code module I've
declared 4 Public variables thusly:

Public aSht as Worksheet
Public sSht... etc.

In my code I then use Set to assign each worksheet to its
variable.

Set aSht = Worksheets("Analysis")

This works fine, however I've found that since I have no control
over which section of the code will run first (determined by the user's
options) I've had to assign the variables more than once, at the start
of several different routines.

Is there anywhere I can put the assignments where I need only use
them once?

I thought of the Workbook_Open() section of ThisWorkbook, but
that's not going to work as it runs before the sheets are loaded.

Any ideas? It's not a biggy, as my code runs successfully and this
may just have to be. I just thought there may be a more elegant &
efficient way to assign them.

See ya
Ken McLennan
Qld, Australia



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default Just wondering

G'day there Tom,

In a general module, not the thisworkbook module, put in your public
variables

then in the ThisworkbookModule

Private Sub workbook_open()

set aSht = thisworkbook.Worksheets("Sheet1")
set sSht = Thisworkbook.Worksheets("Sheet2")
etc.

end Sub

It should work.



Yuppers!!

It worked like a charm. Thanks for your advice, Tom. Much
appreciated.

See ya
Ken McLennan
Qld, Australia
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
We were wondering how to edit an array once it has been set up? Kfalcone Excel Worksheet Functions 3 December 14th 06 04:54 AM
Nothing to do with Excel....wondering if there is a way to check.. Jules Excel Discussion (Misc queries) 1 August 14th 06 05:37 PM
I am wondering if someone could help me solve this equation Miles Excel Discussion (Misc queries) 1 October 25th 05 08:04 AM
Wondering if there is a way? [email protected] Excel Programming 2 June 9th 04 07:36 PM
Wondering If Possible J Excel Programming 0 September 4th 03 04:41 PM


All times are GMT +1. The time now is 10:48 PM.

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"