+ Reply to Thread
Results 1 to 3 of 3

Global Variables

Hybrid View

Guest Global Variables 05-07-2005, 06:06 PM
Guest Re: Global Variables 05-07-2005, 06:06 PM
Guest Re: Global Variables 05-07-2005, 07:06 PM
  1. #1
    Ernst Guckel
    Guest

    Global Variables

    Hello,

    Maybe I just don't get it but I seem to be having a bit of trouble with my
    global variables. Proc. level variables are simple. Module level variables
    are available to the module that they are declared in. Where and how do I
    declare a global variable? I put:

    Public gsFile As String in 'ThisWorkbook' module and in Auto_Open I put:

    gsFile = Thisworkbook.Path & DB_FILE

    The problem is that the variable looses its value once the sub routine
    ends... How do I use the variable and retain its value while the workbook is
    open?

    Ernst.


  2. #2
    Nick Hodge
    Guest

    Re: Global Variables

    Ernst

    Declare the variable using the Public keyword in a standard module, not the
    ThisWorkbook class module. It will then be available to the entire project

    --
    HTH
    Nick Hodge
    Microsoft MVP - Excel
    Southampton, England
    nick_hodgeTAKETHISOUT@zen.co.uk.ANDTHIS

    "Ernst Guckel" <ErnstGuckel@discussions.microsoft.com> wrote in message
    news:EA8A0EB7-1C04-4EEF-8C8D-86B13470B160@microsoft.com...
    > Hello,
    >
    > Maybe I just don't get it but I seem to be having a bit of trouble with
    > my
    > global variables. Proc. level variables are simple. Module level
    > variables
    > are available to the module that they are declared in. Where and how do I
    > declare a global variable? I put:
    >
    > Public gsFile As String in 'ThisWorkbook' module and in Auto_Open I put:
    >
    > gsFile = Thisworkbook.Path & DB_FILE
    >
    > The problem is that the variable looses its value once the sub routine
    > ends... How do I use the variable and retain its value while the workbook
    > is
    > open?
    >
    > Ernst.
    >




  3. #3
    Ernst Guckel
    Guest

    Re: Global Variables

    Thanks. Seems to work...



    "Nick Hodge" wrote:

    > Ernst
    >
    > Declare the variable using the Public keyword in a standard module, not the
    > ThisWorkbook class module. It will then be available to the entire project
    >
    > --
    > HTH
    > Nick Hodge
    > Microsoft MVP - Excel
    > Southampton, England
    > nick_hodgeTAKETHISOUT@zen.co.uk.ANDTHIS
    >
    > "Ernst Guckel" <ErnstGuckel@discussions.microsoft.com> wrote in message
    > news:EA8A0EB7-1C04-4EEF-8C8D-86B13470B160@microsoft.com...
    > > Hello,
    > >
    > > Maybe I just don't get it but I seem to be having a bit of trouble with
    > > my
    > > global variables. Proc. level variables are simple. Module level
    > > variables
    > > are available to the module that they are declared in. Where and how do I
    > > declare a global variable? I put:
    > >
    > > Public gsFile As String in 'ThisWorkbook' module and in Auto_Open I put:
    > >
    > > gsFile = Thisworkbook.Path & DB_FILE
    > >
    > > The problem is that the variable looses its value once the sub routine
    > > ends... How do I use the variable and retain its value while the workbook
    > > is
    > > open?
    > >
    > > Ernst.
    > >

    >
    >
    >


+ 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