PC Review


Reply
Thread Tools Rate Thread

Declaring a local variable once for all subs

 
 
Poniente
Guest
Posts: n/a
 
      29th Sep 2011
Hi,
I'd like to declare a variable once in an referenced xla file, in a
way that all the individual subs in the referring workbook can give it
a local value.
Is this possible?

Regards, Poniente
 
Reply With Quote
 
 
 
 
Mike S
Guest
Posts: n/a
 
      30th Sep 2011
On 9/29/2011 4:11 AM, Poniente wrote:
> Hi,
> I'd like to declare a variable once in an referenced xla file, in a
> way that all the individual subs in the referring workbook can give it
> a local value.
> Is this possible?
> Regards, Poniente


The first answer posted on this page may work for you:

.... create a simple xla called George:
Public harry As Variant
Public Sub setHarry(x)
harry = x
End Sub
Public Function getHarry()
getHarry = harry
End Function
I installed the xla. Then I created Alice.xls with a text box that
called setHarry when it changed and a cell with =getHarry() in it. I
kept it really simple:
Private Sub TextBox1_Change()
Run "george.xla!setHarry", TextBox1
End Sub
I then made a copy of Alice.xls as Bob.xls and ran them both. As
expected, if either workbook changes Harry, both workbooks see the result.

If this approach will work for you and you don't need to set the
variable value from VBA you could try using a constant and assigning its
value in the xla file and removing the set... function.

Private Const harry as string = "abcde12345"

http://stackoverflow.com/questions/3...iple-workbooks



 
Reply With Quote
 
Tim Williams (Theravance)
Guest
Posts: n/a
 
      1st Oct 2011
If you create a variable which is globally accessible it can only have
one value at any given time. If you need local values then you need
local declarations....

Tim

On Sep 29, 4:11*am, Poniente <bost...@gmail.com> wrote:
> Hi,
> I'd like to declare a variable once in an referenced xla file, in a
> way that all the individual subs in the referring workbook can give it
> a local value.
> Is this possible?
>
> Regards, Poniente


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaring subs Public vs Private Rick Microsoft Excel Programming 9 19th Dec 2007 12:30 AM
Calling variable across subs Jeff Microsoft VB .NET 8 18th Apr 2007 11:32 AM
How to declare a variable for several subs David Microsoft Excel Programming 17 18th May 2005 06:38 PM
Declaring instance of class in subs? Brett Microsoft VB .NET 5 11th Mar 2005 05:00 PM
how to make this variable available to other subs djc Microsoft ASP .NET 7 7th Dec 2004 07:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:34 PM.