Using Excel VBA can a constant be available to multiple projects?
Using Excel VBA can a constant be available to multiple projects?
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" <[email protected]> wrote in
message news:[email protected]...
>
> 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
>
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...
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" <[email protected]> wrote in
message news:[email protected]...
>
> 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
>
Now it is working. I thought I needed the path of the ABC in the application run command, and eveidently that messes it up, although it does open ABC, but then not the macro. I just copied exactly what you had and now it works...
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks