Results 1 to 3 of 3

Thread: Use one workbooks variables from another?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    112

    Use one workbooks variables from another?

    Is it possible, while using workbookA, to call a macro from workbookB and access the variables from workbookB's macro?

    workbookB has a macro named newSession()

    I run it from workbookA with:
    Application.Run "workbookB!Module1.newSession"

    newSession populates a Global variable session1
    is it possible to access the variable session1 from the code in workbookA?

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    Luton, UK
    Posts
    178

    Re: Use one workbooks variables from another?

    Define the variable as Public (instead of Dim). eg Workbook B would need a line like :-

    Code:
    Public MyVariable As String
    Regards
    BrianB
    -------------------------------

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    112

    Re: Use one workbooks variables from another?

    How would you refer to the variable from the other workbook?

    If session1 is a string, while the project is running I can go to the immediate window and type 'print session1' and it will print fine. If I activate any of the sheets in the other project and attempt the same print command, it returns a null value. Switch back the the original project and it retains its original value.

    This happens with the variable declared both public and global (which I guess is the same in vba)

Posting Permissions

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



Click Here to Expand Forum to Full Width