Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Call Public constants from other project

Hi,

Is it possible to refer to / call a Public constant in another project?
If so, how?

The idea:
I have some constants that change often and are used in alsmost all of my
projects.
I want to store them in one place, and modify them (if needed) in one place,
so they can kick in in the other projects that refer them.

Thanks!

M

--
Message posted via http://www.officekb.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Call Public constants from other project

Most efficent way is to set a reference to the project containing the
constants and call them directly. However that's not always practical,
another way

' in Constants.xls
Public Const cNUM As Long = 123
Public Const cTXT As String = "abc"

Public Function getConstant(sName As String) As Variant
Select Case sName
Case "cNUM": getConstant = cNUM
Case "cTXT": getConstant = cTXT
Case Else: getConstant = -99
End Select
End Function

'in another project

Sub test()
Dim c
c = Application.Run("Constants.xls!getConstant", "cNUM")
MsgBox c
End Sub


But why not put your constants in cells, eg

c = Workbooks("Constants.xls").Worksheets("Sheet1").Ra nge("A1")

Regards,
Peter T


"Michiel via OfficeKB.com" <u40062@uwe wrote in message
news:9e487bfeaba18@uwe...
Hi,

Is it possible to refer to / call a Public constant in another project?
If so, how?

The idea:
I have some constants that change often and are used in alsmost all of my
projects.
I want to store them in one place, and modify them (if needed) in one
place,
so they can kick in in the other projects that refer them.

Thanks!

M

--
Message posted via http://www.officekb.com



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Call Public constants from other project

Hi Peter T.

Thank you this is a great solution, thak you for sharing!

And yes putting them in a workbook could be a solution but I actually intend
to put them in the code attached to Personal.xls. Then it will be always
available and not "pollutingly visible".

M.



Peter T wrote:
Most efficent way is to set a reference to the project containing the
constants and call them directly. However that's not always practical,
another way
......................
But why not put your constants in cells, eg


--
Message posted via http://www.officekb.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
Public variable (or Public Const?) Tim Williams[_2_] Excel Programming 0 April 23rd 09 06:33 AM
How to call functions of a DLL in Excel and in a .net project Dartish Excel Programming 1 May 27th 06 11:28 PM
call a excel function from a vb project Alex281 Excel Programming 2 March 29th 06 05:22 AM
Referencing Call to Another Project Phil B[_2_] Excel Programming 4 August 1st 05 03:52 AM
project wide compconditional compile constants Erich Neuwirth Excel Programming 4 May 17th 04 10:48 PM


All times are GMT +1. The time now is 04:39 AM.

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"