+ Reply to Thread
Results 1 to 4 of 4

VBA storing variables

  1. #1
    Registered User
    Join Date
    06-26-2019
    Location
    Freeport, Tx
    MS-Off Ver
    Microsoft 2016 32-bit
    Posts
    32

    VBA storing variables

    Greetings,

    I have a VB program in Excel, and I need to store the value of two variables between runs of the macros in the workbook. The workbook will be closed and open at various times.

    Currently, I have the VB program create a sheet called "Data" then hide it. I then place these values in cells of worksheet "Data" then recall when needed. I was just wondering if there was a better method.

    Thank you,

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,364

    Re: VBA storing variables

    You could make the Data sheet xlVeryHidden so it's less easy to access.

    Or you could write the variables to a text file.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: VBA storing variables

    There are few ways to do it. But what you are using is probably the easiest.

    1. If you need to access these variables without opening workbook. You could store it in text file.
    Ex:
    Please Login or Register  to view this content.
    2. You could write variables to registry... but personally I don't like using registry for this purpose. Check link for how to read/write to registry.
    https://vba-corner.livejournal.com/3054.html
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,598

    Re: VBA storing variables

    Please Login or Register  to view this content.
    Ben Van Johnson

+ 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] Storing & retrieving variables - best practice?
    By BusterT in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-09-2018, 06:23 PM
  2. Storing variables as string or as variables in array performance
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-20-2017, 08:35 AM
  3. [SOLVED] MS-Word storing variables in VBA (non-Excel)
    By HeyInKy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-04-2015, 09:42 AM
  4. Handling and storing values on global variables while running several macros
    By Pichingualas in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-23-2012, 10:55 AM
  5. Storing variables from a Userform in an Add In
    By solnajeff in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-01-2012, 12:56 PM
  6. Storing Variables for use in different Sub routines
    By tomlancaster in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2010, 08:11 AM
  7. Storing and using objects in variables.
    By h20skee in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-16-2008, 06:36 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