ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   public const availability? (https://www.excelbanter.com/excel-programming/364600-public-const-availability.html)

lcoreyl[_22_]

public const availability?
 

Using Excel VBA can a constant be available to multiple projects?


--
lcoreyl
------------------------------------------------------------------------
lcoreyl's Profile: http://www.excelforum.com/member.php...fo&userid=2042
View this thread: http://www.excelforum.com/showthread...hreadid=552950


Tom Ogilvy

public const availability?
 
Not usually. You would need to set a reference from the workbooks that want
to use the constant to the workbook that defines the constant. Probably not
something you want to do.

A possible workaround could be:
In the workbook that contains the constant, you could put a sub that returns
its value

In a general module a workbook named ABC.xls as an example.

Public Const MyVal as Long = 10

Pubic Function ReturnMyVal()
ReturnMyVal = MyVal
End Function

then in the other workbook

v = Application.Run( "ABC.xl1!ABC")
msgbox v

now v will hold the value of the constant.
--
Regards,
Tom Ogilvy



"lcoreyl" wrote in
message ...

Using Excel VBA can a constant be available to multiple projects?


--
lcoreyl
------------------------------------------------------------------------
lcoreyl's Profile:

http://www.excelforum.com/member.php...fo&userid=2042
View this thread: http://www.excelforum.com/showthread...hreadid=552950




lcoreyl[_23_]

public const availability?
 

keep getting "macro not found"

tried creating (in the book with the constant) a macro named ABC wit
just the function in it, and still get the same error..

--
lcorey
-----------------------------------------------------------------------
lcoreyl's Profile: http://www.excelforum.com/member.php...nfo&userid=204
View this thread: http://www.excelforum.com/showthread.php?threadid=55295


Tom Ogilvy

public const availability?
 
There was a typo on the Application.Run string and in the spelling of Public
for the function - but fixing those I recreated the situation

In the workbook named ABC.xls, in Module1

Public Const MyVal As Long = 10

Public Function ReturnMyVal()
ReturnMyVal = MyVal
End Function

in another workbook

Sub GettheValue()
v = Application.Run("ABC.xls!ReturnMyVal")
MsgBox v
End Sub

the message box displayed 10

--
Regards,
Tom Ogilvy


"lcoreyl" wrote in
message ...

keep getting "macro not found"

tried creating (in the book with the constant) a macro named ABC with
just the function in it, and still get the same error...


--
lcoreyl
------------------------------------------------------------------------
lcoreyl's Profile:

http://www.excelforum.com/member.php...fo&userid=2042
View this thread: http://www.excelforum.com/showthread...hreadid=552950




lcoreyl[_25_]

public const availability?
 

I copied those directly into two workbooks and it still doesn't work.
It does open ABC.xls, but then says "The macro 'ABC.xls!ReturnMyVal
can not be found"

--
lcorey
-----------------------------------------------------------------------
lcoreyl's Profile: http://www.excelforum.com/member.php...nfo&userid=204
View this thread: http://www.excelforum.com/showthread.php?threadid=55295


lcoreyl[_26_]

public const availability?
 

Now it is working. I thought I needed the path of the ABC in th
application run command, and eveidently that messes it up, although i
does open ABC, but then not the macro. I just copied exactly what yo
had and now it works..

--
lcorey
-----------------------------------------------------------------------
lcoreyl's Profile: http://www.excelforum.com/member.php...nfo&userid=204
View this thread: http://www.excelforum.com/showthread.php?threadid=55295



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com