+ Reply to Thread
Results 1 to 5 of 5

public const availability?

  1. #1
    Registered User
    Join Date
    10-28-2003
    Posts
    21

    public const availability?

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

  2. #2
    Tom Ogilvy
    Guest

    Re: 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" <[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
    >




  3. #3
    Registered User
    Join Date
    10-28-2003
    Posts
    21

    no luck

    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...

  4. #4
    Tom Ogilvy
    Guest

    Re: 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" <[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
    >




  5. #5
    Registered User
    Join Date
    10-28-2003
    Posts
    21

    Thanks!

    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...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1