Results 1 to 4 of 4

Thread: EXCEL: How to: Pass Global Variables from Window_Open event: Resolved

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Resolved EXCEL: How to: Pass Global Variables from Window_Open event: Resolved

    Esteemed Forum Participants and Lurkers:
    ===============================

    Thanks to Savelinus for helping me get started, but I didn't get very far. Here is the code I have so far, but I get an error when I try to reference the variable I was trying to make Global:
    Code:
    Option Explicit
    'Module:  ThisWorkbook(Code)
    '
    Public G_STR As String    'Define the Global Variable
    '
    Private Sub Workbook_Open()    'The EVENT for Opening the Workbook
        Dim astr As String
        
        ' Show that the Workbook has opened
        astr = ActiveSheet.Name
        MsgBox ("Hello, World! Sheet " & astr & " is OPEN!")
        ' Show that the Variable has been defined - at least locally
        G_STR = "THIS IS A GLOBAL TEST STRING"
        MsgBox (G_STR)
        
    End Sub
    Code:
    Option Explicit
    'Module:  Module1(Code)
    '
    'MACRO to test Initialized Global Variables - View the initialized Global
    Sub G_Test()
      MsgBox (G_STR)  '<<<<     Compile error: Variable not defined
    End Sub
    So if I an going to use the Workbook_Open event to initialize some global variables, how do I get it to work in other modules?

    Thank you for your gracious comments, suggestions, and assistance.
    Last edited by Webtest; May 24th, 2005 at 11:57 AM. Reason: [RESOLVED]
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

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