LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Persistent data in an Add-in

Hi Bura,
I believe global variables lose their value as soon as your code stops
running. Therefore, to maintain a variable between macros, I generally use
one of the 3 following approaches:
1. Save and retrieve it to/from the registry, if it is something that is
global across a lot of workbooks.
SaveSetting appname, section, key, setting
GetSetting(appname, section, key[, default])
2. If there are a lot of variables (several dozen or more), save them in a
separate workbook in a folder where your macro is saved, and use method #1
above to save the location of this workbook in the registry.
3. Save it in the user's workbook on a hidden worksheet. I generally add a
worksheet ("Scratch") to the template and use it to save all kinds of
constants and formulas to calculate labels for charts, etc. If your users
are running your macro on a workbook of their own that was not built from a
template that you provided, then methods #1 and #2 may be the only option.

I generally never make any changes at runtime to an add-in, since Excel
would then have to save the add-in every time that the user exits Excel. If
not done automatically, and the user is prompted to save and they say "No",
then the global variable is lost. Being prompted to save an add-in tends to
make a user think that they have been infected with a virus (since an add-in
is generally thought of as additional functionality, and everybody knows
that code is not supposed to change - unless it has been infected with a
virus, of course!).
--
Regards,
Bill


"Bura Tino" wrote in message
...
Hi,

Is it better to use a global variable or a cell in an add-ins worksheet to
store a value?

Using a global variable seems cleaner, but I'm concerned that the project
may get reset and the value would be lost.
Using a cell in a worksheet seems ugly, but so far seems to work for me.

Are there any hidden dangers in the latter approach?

Thank you,

Bura




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel ODBC driver created table/data not persistent Farid Z Excel Discussion (Misc queries) 2 May 19th 10 05:14 PM
Data Entry Online, Data Format, Data Conversion and Data EntryServices through Data Entry Outsourcing [email protected] Excel Discussion (Misc queries) 0 March 20th 08 12:45 PM
Persistent External File Links Vulch1968 Setting up and Configuration of Excel 1 April 28th 07 03:06 AM
How to Delete a persistent Toolbar? alainr Excel Discussion (Misc queries) 6 October 6th 05 04:29 PM
Persistent Excel toolbar Mohamed ABOU-ZAID Excel Programming 0 October 1st 03 04:45 PM


All times are GMT +1. The time now is 07:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"