+ Reply to Thread
Results 1 to 3 of 3

Public/ Global variables

  1. #1
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Public/ Global variables

    Just a quick question I think.....

    Public Variables
    My understanding was that these are variables which can be used anywhere within the workbook however Ive heard talk of them being available to other workbooks as well?

    This seems to be backed up by the following Microsoft article
    http://support.microsoft.com/kb/141693

    which (in the Public Scope para) states "To make a public variable available to other workbooks, from a new workbook select the workbook containing the public variable in the Available References box of the References dialog box (from a module sheet, click References on the Tools menu)."

    Now Ive tried everything to get this to work but cannot seem to share a variable across workbooks, I did manage to "Reference the 2nd workbook" but I cant get it to take the value of the Public Variable on.

    Any thoughts/tips/ideas?
    If someone has helped you then please add to their Reputation

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Public/ Global variables

    You have not shown us what you tried to it's impossible to say whats wrong.

    I just did a simple test with two workbooks.
    Book3.xlsm with the vbaproject named as PBook3

    Please Login or Register  to view this content.
    Book2.xlsm with reference to PBook3
    Please Login or Register  to view this content.
    You can run loadvar or showvar in either workbook to see contents and where the code is running from.

    What's the reason for sharing variables across workbooks?
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,980

    Re: Public/ Global variables

    BTW, if you put the Public variables in the ThisWorkbook module of the workbook, you can refer to them as members of that workbook without having to set a reference. Not convinced it's a good idea though!
    Everyone who confuses correlation and causation ends up dead.

+ 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. Problem with public global declared variables
    By vonb3ta in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-03-2013, 07:20 AM
  2. Declaring a variable as Public or Global
    By saji in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-08-2013, 07:55 PM
  3. [SOLVED] Global/Public
    By Fox via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-26-2006, 03:50 PM
  4. [SOLVED] public or global array
    By shishi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-06-2006, 05:35 PM
  5. Public vs Global
    By quartz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-09-2005, 03:06 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