Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Global Variable in Excel VBA


Hi!

Please help me on the following issue:

I want to declare a global variable in an Excel workbook.

I used
"Public zIND As Boolean"

in the code for "ThisWorkbook".

But when I try to call its value, that is assigned on the workbook open
event, I can't see it or change it from another sheet code - I want to
change its values when a change occurs in a worksheet, but it's not
possible because it seems that I can't see it from another worksheet.


Thanks in advance,
Chris


--
loopoo
------------------------------------------------------------------------
loopoo's Profile: http://www.excelforum.com/member.php...o&userid=28792
View this thread: http://www.excelforum.com/showthread...hreadid=493738

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Global Variable in Excel VBA

Hi Chris,

As the "ThisWorkbook" is a pre-built Class module you can refer to a
variable declared as public out side the class like this

ThisWorkbook.zIND = True

msgbox ThisWorkbook.zIND

Or use a Property Let/Get pair.

However it has been recommended by others to put as little as possible in
the ThisWorkbook module, because if anything gets corrupted could mean
re-building from scratch.

So put your public variable in a normal module.

Regards,
Peter T

"loopoo" wrote in
message ...

Hi!

Please help me on the following issue:

I want to declare a global variable in an Excel workbook.

I used
"Public zIND As Boolean"

in the code for "ThisWorkbook".

But when I try to call its value, that is assigned on the workbook open
event, I can't see it or change it from another sheet code - I want to
change its values when a change occurs in a worksheet, but it's not
possible because it seems that I can't see it from another worksheet.


Thanks in advance,
Chris


--
loopoo
------------------------------------------------------------------------
loopoo's Profile:

http://www.excelforum.com/member.php...o&userid=28792
View this thread: http://www.excelforum.com/showthread...hreadid=493738



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Global Variable in Excel VBA

Don't add it to ThisWorkbook, add it to a standard code module.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"loopoo" wrote in
message ...

Hi!

Please help me on the following issue:

I want to declare a global variable in an Excel workbook.

I used
"Public zIND As Boolean"

in the code for "ThisWorkbook".

But when I try to call its value, that is assigned on the workbook open
event, I can't see it or change it from another sheet code - I want to
change its values when a change occurs in a worksheet, but it's not
possible because it seems that I can't see it from another worksheet.


Thanks in advance,
Chris


--
loopoo
------------------------------------------------------------------------
loopoo's Profile:

http://www.excelforum.com/member.php...o&userid=28792
View this thread: http://www.excelforum.com/showthread...hreadid=493738



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Global Variable in Excel VBA

Move the variable's declaration to a module
--
Gary's Student


"loopoo" wrote:


Hi!

Please help me on the following issue:

I want to declare a global variable in an Excel workbook.

I used
"Public zIND As Boolean"

in the code for "ThisWorkbook".

But when I try to call its value, that is assigned on the workbook open
event, I can't see it or change it from another sheet code - I want to
change its values when a change occurs in a worksheet, but it's not
possible because it seems that I can't see it from another worksheet.


Thanks in advance,
Chris


--
loopoo
------------------------------------------------------------------------
loopoo's Profile: http://www.excelforum.com/member.php...o&userid=28792
View this thread: http://www.excelforum.com/showthread...hreadid=493738


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Global Variable in Excel VBA


Thank you all for your help.

It's working fine now.

Chris

--
loopo
-----------------------------------------------------------------------
loopoo's Profile: http://www.excelforum.com/member.php...fo&userid=2879
View this thread: http://www.excelforum.com/showthread.php?threadid=49373

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
Global Variable Patrick Simonds Excel Programming 8 October 6th 05 12:39 AM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM
Excel Application Level Global Variable wesbird Excel Programming 1 June 21st 05 12:52 AM
Global Variable -- Excel / VBA Adam1 Chicago Excel Discussion (Misc queries) 3 February 23rd 05 12:03 AM
Excel Global Variable Setting John Baker Excel Programming 8 November 25th 03 02:34 PM


All times are GMT +1. The time now is 02:54 PM.

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

About Us

"It's about Microsoft Excel"