+ Reply to Thread
Results 1 to 4 of 4

Global variable not retaining value

  1. #1
    Forum Contributor
    Join Date
    09-05-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2003 Excel 2007
    Posts
    383

    Global variable not retaining value

    Good Morning All,

    I'm having a problem with a global value retaining its value between the workbook_open event and module code.

    I have the following declared above everything else in my Thisworkbook module
    Please Login or Register  to view this content.
    At the end of my workbookopen event I have
    Please Login or Register  to view this content.
    when debugging (f8) PUB_PWORD has a value of 0 as expected until it hits the ends sub where it becomes 'empty'

    I have a module that is checking the value of PUB_PWORD and i its not 1 running code before setting it to the value of 1

    I know I could store the value within a worksheet cell but as I only needed to retain value for the user session didn't think it would be required.

    any ideas why this might be failing?
    Last edited by Kramxel; 07-07-2015 at 06:51 AM.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Global variable not retaining value

    Hi, Kramxel,

    Global Variables should be placed in a Standard module. In ThisWorkbook they would only be known in the module not in the workbook. Please add the missing backslash at the code-tag in your second procedure (if not done by now).

    Ciao,
    Holger
    Last edited by HaHoBe; 07-07-2015 at 07:03 AM. Reason: misread All, ediited post later on
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Global variable not retaining value

    I think you should put the public variables in a regular module, not in ThisWorkbook module
    If you are pleased with a member's answer then use the Star icon to rate it.

  4. #4
    Forum Contributor
    Join Date
    09-05-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2003 Excel 2007
    Posts
    383

    Re: Global variable not retaining value

    AHA! thank you solved the problem perfectly

    you're all geniuses!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Global Variable is not retaining its value
    By mahmud1280 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-19-2015, 07:32 AM
  2. [SOLVED] Global variable declared in Userform. Variable value is not sticking
    By timtim89 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-25-2012, 08:50 AM
  3. Replies: 3
    Last Post: 09-06-2005, 04:05 AM
  4. Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  5. Replies: 1
    Last Post: 07-08-2005, 09:05 PM

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