Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default How to handle persistent properties in Excel VBA 2003

Hi all,
I need to store persistent configuration settings of a custom Excel 2003
add-in.
Which is best way to do this in your opinion?
I can suppose these possible solutions:
1) write configuration settings in a text file and load it every time is
needed
2) write settings in a "hidden" cell or worksheet (but I don't like this);
is there another way to store this information inside the .xls file?

Thanks in advance,

faffo1980
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default How to handle persistent properties in Excel VBA 2003

1) In a hidden worksheet that is protect. Make the cells readable but not
writable
2) Store text in a module as comments. Again you can make th emodule
invisable. the text can be read from VBA code.

"faffo1980" wrote:

Hi all,
I need to store persistent configuration settings of a custom Excel 2003
add-in.
Which is best way to do this in your opinion?
I can suppose these possible solutions:
1) write configuration settings in a text file and load it every time is
needed
2) write settings in a "hidden" cell or worksheet (but I don't like this);
is there another way to store this information inside the .xls file?

Thanks in advance,

faffo1980

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default How to handle persistent properties in Excel VBA 2003

Hi Joel,
thanks a lot for your reply.
What do you mean with "Store text in a module AS A COMMENT"?
Sorry for the question but I'm very new wih VBA..How can I read/modify
comment withiin a module?

Thanks again

Regards

"Joel" wrote:

1) In a hidden worksheet that is protect. Make the cells readable but not
writable
2) Store text in a module as comments. Again you can make th emodule
invisable. the text can be read from VBA code.

"faffo1980" wrote:

Hi all,
I need to store persistent configuration settings of a custom Excel 2003
add-in.
Which is best way to do this in your opinion?
I can suppose these possible solutions:
1) write configuration settings in a text file and load it every time is
needed
2) write settings in a "hidden" cell or worksheet (but I don't like this);
is there another way to store this information inside the .xls file?

Thanks in advance,

faffo1980

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default How to handle persistent properties in Excel VBA 2003

I assumed you were storing text strings. With text you can always remove the
single quote comments.

Cpearson in the website below gives lots of examples for reading/writing to
modules

http://www.cpearson.com/Excel/vbe.aspx


so you can simply put comments into the modules

'line1
'line2
'line3


Then when you read the lines remove the comments

inputline = mid(MyString,2) this will skip the 1st character when reading
the line.


"faffo1980" wrote:

Hi Joel,
thanks a lot for your reply.
What do you mean with "Store text in a module AS A COMMENT"?
Sorry for the question but I'm very new wih VBA..How can I read/modify
comment withiin a module?

Thanks again

Regards

"Joel" wrote:

1) In a hidden worksheet that is protect. Make the cells readable but not
writable
2) Store text in a module as comments. Again you can make th emodule
invisable. the text can be read from VBA code.

"faffo1980" wrote:

Hi all,
I need to store persistent configuration settings of a custom Excel 2003
add-in.
Which is best way to do this in your opinion?
I can suppose these possible solutions:
1) write configuration settings in a text file and load it every time is
needed
2) write settings in a "hidden" cell or worksheet (but I don't like this);
is there another way to store this information inside the .xls file?

Thanks in advance,

faffo1980

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Handling persistent properties

Hi faffo198,

The best way to do this is to use the registry functions offered by Excel. I know, writing stuff to the registry sounds scary, but it's safe if you use Excel's built-in functions. The three functions that you will be using are SaveSetting, GetSetting and DeleteSetting.

SaveSetting allows you to store values in the registry, GetSetting allows you to retrieve those values and you use DeleteSetting to clean up once you are done. These three functions require an application name, a section name and a key name (optional for DeleteSetting). My suggestion is to set the first two using global constants:
Global Const sAppName = "MyAddin"
Global Const sSectionName = "Config"

Then define three functions:
'Retrieve the value of the "key" registry key under sAppName\sSectionName
Public Function get_value(key As String) As String

get_value = GetSetting(sAppName, sSectionName, key)
End Function

'Set the value of the "key" registry key under sAppName\sSectionName
Public Sub set_value(key As String, key_value As String)

SaveSetting sAppName, sSectionName, key, key_value
End Sub

'Delete the sAppName\sSectionName registry path (will delete all keys in that path too)
Sub clear_registry()

On Error Resume Next
DeleteSetting sAppName, sSectionName
On Error GoTo 0
End Sub

And you can now save and restore configuration settings in a persistent manner. Example:

Sub LastUsed()
dim last_used as string

'Retrieve last used date
On Error Resume Next
last_user = get_value("LastUsed")
On Error GoTo 0

MsgBox "This add-in was last used on " & last_used

'Set new last used date
set_value "LastUsed", CStr(Now)
End Sub


Sub CleanUp()

'Erase all registry keys stored in sAppName\sSectionName
'Don't use if you wish for the data to persist after you close Excel
clear_registry
End Sub

Cheers,

Benoit

On Monday, August 10, 2009 6:00 AM faffo198 wrote:


Hi all,
I need to store persistent configuration settings of a custom Excel 2003
add-in.
Which is best way to do this in your opinion?
I can suppose these possible solutions:
1) write configuration settings in a text file and load it every time is
needed
2) write settings in a "hidden" cell or worksheet (but I do not like this);
is there another way to store this information inside the .xls file?

Thanks in advance,

faffo1980



On Monday, August 10, 2009 6:07 AM Joe wrote:


1) In a hidden worksheet that is protect. Make the cells readable but not
writable
2) Store text in a module as comments. Again you can make th emodule
invisable. the text can be read from VBA code.

"faffo1980" wrote:



On Monday, August 10, 2009 6:48 AM faffo198 wrote:


Hi Joel,
thanks a lot for your reply.
What do you mean with "Store text in a module AS A COMMENT"?
Sorry for the question but I am very new wih VBA..How can I read/modify
comment withiin a module?

Thanks again

Regards

"Joel" wrote:



On Monday, August 10, 2009 6:57 AM Joe wrote:


I assumed you were storing text strings. With text you can always remove the
single quote comments.

Cpearson in the website below gives lots of examples for reading/writing to
modules

http://www.cpearson.com/Excel/vbe.aspx


so you can simply put comments into the modules

'line1
'line2
'line3


Then when you read the lines remove the comments

inputline = mid(MyString,2) this will skip the 1st character when reading
the line.


"faffo1980" wrote:



Submitted via EggHeadCafe - Software Developer Portal of Choice
Book Review: Excel 2010 - The Missing Manual [OReilly]
http://www.eggheadcafe.com/tutorials...l-oreilly.aspx

Reply
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
Setting up Excel (2003) to handle users with different editing abilities Alan[_38_] Excel Programming 2 October 24th 07 12:16 AM
excel 2003 Reading workbook properties / details from an XLA how do you do it? brad Excel Programming 0 September 14th 07 12:34 AM
Excel 2003 Context menu handle [email protected] Excel Discussion (Misc queries) 3 June 4th 07 02:48 PM
How to modify fill handle properties? ashish Excel Discussion (Misc queries) 2 March 15th 06 06:05 AM
How to modify fill handle properties? sunny Excel Discussion (Misc queries) 3 March 8th 06 11:14 AM


All times are GMT +1. The time now is 05:44 PM.

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

About Us

"It's about Microsoft Excel"