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 Common ?

VBA provides ways to declare variables that are “known”:
within a given procedure
to all procedures in a module
to all procedures in a project

Is there a way to declare variables that are known to all ope
projects?

Thank

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Global Common ?

You could have a function in the workbook that returns the value of that
variable, then call that function using application.Run

Otherwise, you would need to create a reference to the workbook containing
the public variable.

--
Regards,
Tom Ogilvy

MWE wrote in message
...
VBA provides ways to declare variables that are "known":
within a given procedure
to all procedures in a module
to all procedures in a project

Is there a way to declare variables that are known to all open
projects?

Thanks


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Global Common ?

Tom, can you give an example? I having trouble getting
this to work. In Macro1, I want to define x = 8. In
Macro2, I want to get the value of x.


-----Original Message-----
You could have a function in the workbook that returns

the value of that
variable, then call that function using application.Run

Otherwise, you would need to create a reference to the

workbook containing
the public variable.

--
Regards,
Tom Ogilvy

MWE wrote in

message
...
VBA provides ways to declare variables that

are "known":
within a given procedure
to all procedures in a module
to all procedures in a project

Is there a way to declare variables that are known to

all open
projects?

Thanks


---
Message posted from http://www.ExcelForum.com/



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Global Common ?

Tommy,

Use a variable declaration like the following, in a standard code
module, outside of and before any procedu

Public X As Long

Then, go to the Tools menu, choose VBA Project Properties, and
give a unique name to the project e.g., MyProject.

Then in the workbook that will read or write this variable's
value, go to the Tools menu, choose References, and put a check
next to MyProject. Finally, you can use the variable X in the
other project with code like

MyProject.X = 123


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Tommy T" wrote in message
...
Tom, can you give an example? I having trouble getting
this to work. In Macro1, I want to define x = 8. In
Macro2, I want to get the value of x.


-----Original Message-----
You could have a function in the workbook that returns

the value of that
variable, then call that function using application.Run

Otherwise, you would need to create a reference to the

workbook containing
the public variable.

--
Regards,
Tom Ogilvy

MWE wrote in

message
...
VBA provides ways to declare variables that

are "known":
within a given procedure
to all procedures in a module
to all procedures in a project

Is there a way to declare variables that are known to

all open
projects?

Thanks


---
Message posted from http://www.ExcelForum.com/



.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Global Common ?

Unless you have a conflicting variable with the same name, you can just use

X

myvar = X

for example.

(once the reference is created).

--
Regards,
Tom Ogilvy

Chip Pearson wrote in message
...
Tommy,

Use a variable declaration like the following, in a standard code
module, outside of and before any procedu

Public X As Long

Then, go to the Tools menu, choose VBA Project Properties, and
give a unique name to the project e.g., MyProject.

Then in the workbook that will read or write this variable's
value, go to the Tools menu, choose References, and put a check
next to MyProject. Finally, you can use the variable X in the
other project with code like

MyProject.X = 123


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Tommy T" wrote in message
...
Tom, can you give an example? I having trouble getting
this to work. In Macro1, I want to define x = 8. In
Macro2, I want to get the value of x.


-----Original Message-----
You could have a function in the workbook that returns

the value of that
variable, then call that function using application.Run

Otherwise, you would need to create a reference to the

workbook containing
the public variable.

--
Regards,
Tom Ogilvy

MWE wrote in

message
...
VBA provides ways to declare variables that

are "known":
within a given procedure
to all procedures in a module
to all procedures in a project

Is there a way to declare variables that are known to

all open
projects?

Thanks


---
Message posted from http://www.ExcelForum.com/



.







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Global Common ?

Assuming you are asking about the none reference method:

In Book2.xls

Public x as long

Sub SetVal()
x = 8
End Sub


Function Macro1()
Macro1 = 8
End Function

In Book1.xls

Sub Macro2()
msgbox Application.Run("Book2.xls!Macro1")
End Sub

Assumes SetVal has already been run in Book2.xls

--
Regards,
Tom Ogilvy

Tommy T wrote in message
...
Tom, can you give an example? I having trouble getting
this to work. In Macro1, I want to define x = 8. In
Macro2, I want to get the value of x.


-----Original Message-----
You could have a function in the workbook that returns

the value of that
variable, then call that function using application.Run

Otherwise, you would need to create a reference to the

workbook containing
the public variable.

--
Regards,
Tom Ogilvy

MWE wrote in

message
...
VBA provides ways to declare variables that

are "known":
within a given procedure
to all procedures in a module
to all procedures in a project

Is there a way to declare variables that are known to

all open
projects?

Thanks


---
Message posted from http://www.ExcelForum.com/



.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Global Common ?

The dialogue on this thread has been most interesting. But I am still
bit confused. Let me clarify what I am trying to do:

I have a number of applications, let's call them A1, A2 and A3, tha
use 30 or so procedures that are specific to these applications. Thes
procedures are stored in a module called A_Proc_Lib. Each applicatio
has its own copy of this module. Each application has its ow
identical declaration of Public variables that are also used by th
A_Proc_Lib procedures.

A1, A2 and A3, and A_Proc_Lib procedures also use some genera
procedures stored in my Personal.xls. Procedures in Personal.xl
communicate with the calling application or prcedure only throug
passed parameters. A1, A2 and A3 all Reference Personal.xls Thing
seem to work fine.

To reduce maintenance of A_Proc_Lib and potentially different versions
I want to put A_Proc_Lib somewhere where any "A" application ca
reference it. I tried putting A_Proc_Lib into Personal.xls but th
Public variables were not "understood" by Personal.xls (compile
errors). I tried creating an Add-In containing A_Proc_Lib (this is
very appealing solution), but had the same problems as wit
Personal.xls (I guess that makes sense). I do not want to eliminat
the inter-procedure communications through public/common.

Any Further thoughts?

Thank

--
Message posted from http://www.ExcelForum.com

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Global Common ?

I'm intrigued by the statement that you got an error when you put the public
variables in Personal.xls. This is just another workbook, so if the
variables were okay elsewhere, they should be okay in Personal (and it
should be much the same for an addin).

Where and how did you declare these variables, and what error do you get?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"MWE " wrote in message
...
The dialogue on this thread has been most interesting. But I am still a
bit confused. Let me clarify what I am trying to do:

I have a number of applications, let's call them A1, A2 and A3, that
use 30 or so procedures that are specific to these applications. These
procedures are stored in a module called A_Proc_Lib. Each application
has its own copy of this module. Each application has its own
identical declaration of Public variables that are also used by the
A_Proc_Lib procedures.

A1, A2 and A3, and A_Proc_Lib procedures also use some general
procedures stored in my Personal.xls. Procedures in Personal.xls
communicate with the calling application or prcedure only through
passed parameters. A1, A2 and A3 all Reference Personal.xls Things
seem to work fine.

To reduce maintenance of A_Proc_Lib and potentially different versions,
I want to put A_Proc_Lib somewhere where any "A" application can
reference it. I tried putting A_Proc_Lib into Personal.xls but the
Public variables were not "understood" by Personal.xls (compiler
errors). I tried creating an Add-In containing A_Proc_Lib (this is a
very appealing solution), but had the same problems as with
Personal.xls (I guess that makes sense). I do not want to eliminate
the inter-procedure communications through public/common.

Any Further thoughts?

Thanks


---
Message posted from http://www.ExcelForum.com/



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Global Common ?

Bob: I did not keep very good notes yesterday when I ran into thes
problems. Things got so screwed up that Excel was puking all the time
I eventually had to reinstall Excel and am now running a slightl
different version of Excel2000 (no recent updates for security stuff).
Strangely, I can not duplicate the type of compiler errors I wa
getting yesterday when I placed the Public statements in Personal.xl
(I copied A_Proc_Lib into Personal.xls and placed a copy of the Publi
statements at the top of that module). I replicated that work a fe
minutes ago. It does not work, i.e., the public common in Personal.xl
is a different public common than the one in the base application, bu
it does NOT gnerate compiler errors now.

Thanks for taking a look

MW

--
Message posted from http://www.ExcelForum.com

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 dhstein Excel Discussion (Misc queries) 2 October 30th 09 01:03 PM
Combining two ranges based on common a common value ahmed[_3_] Excel Discussion (Misc queries) 5 April 18th 09 05:04 PM
Common footer but not common margins please -(Page 1 of 2) etc RajenRajput1 Excel Discussion (Misc queries) 9 August 26th 08 06:56 PM
global changes Eclaires Excel Worksheet Functions 2 March 17th 08 01:03 PM
Global Function T.R. Excel Discussion (Misc queries) 1 February 16th 05 07:03 PM


All times are GMT +1. The time now is 07:27 AM.

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"