Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
"Config file"
Hi,
I am writing an add-in and one of its first duty should be to be able to read a "config file" containing several settings necessary to the other procedures in the add-in. Another procedure in the add-in will also allow the user to change and save new settings into this same config file. I really don't know where to start? How would you go about it? Thank you. Eric |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
"Config file"
You could use an INI file.
Private Declare Function GetPrivateProfileInt Lib "kernel32" _ Alias "GetPrivateProfileIntA" _ (ByVal lpApplicationName As String, _ ByVal lpKeyName As String, _ ByVal nDefault As Long, _ ByVal lpFileName As String) As Long Private Declare Function GetPrivateProfileString Lib "kernel32" _ Alias "GetPrivateProfileStringA" _ (ByVal lpApplicationName As String, _ ByVal lpKeyName As Any, _ ByVal lpDefault As String, _ ByVal lpReturnedString As String, _ ByVal nSize As Long, _ ByVal lpFileName As String) As Long Private Declare Function WritePrivateProfileString Lib "kernel32" _ Alias "WritePrivateProfileStringA" _ (ByVal lpApplicationName As String, _ ByVal lpKeyName As Any, _ ByVal lpString As Any, _ ByVal lpFileName As String) As Long and use like so cSubItems = GetPrivateProfileInt("myApp", "Id", 0, Filename) and Dim sKeyValue As String Dim nLen As Long sKeyValue = Space$(255) nLen = GetPrivateProfileString(AppId, "myApp", "Id", "Not Found", _ sKeyValue, Len(sKeyValue), Filename) If nLen = Len(sKeyValue) - 1 Then 'means sKeyValue not long enough sKeyValue = Space$(Len(sKeyValue) + 100) Else sKeyValue = Left(sKeyValue, nLen) End If -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Eric" wrote in message ... Hi, I am writing an add-in and one of its first duty should be to be able to read a "config file" containing several settings necessary to the other procedures in the add-in. Another procedure in the add-in will also allow the user to change and save new settings into this same config file. I really don't know where to start? How would you go about it? Thank you. Eric |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
"Config file"
Another option is to save the settings in a worksheet in the addin.
Remember that you'll want to save the workbook after you've made a change to the settings (that you want to keep). Or you could look at GetSetting and SaveSetting in VBA's help. These allow you to retrieve and save settings from the windows registry. Eric wrote: Hi, I am writing an add-in and one of its first duty should be to be able to read a "config file" containing several settings necessary to the other procedures in the add-in. Another procedure in the add-in will also allow the user to change and save new settings into this same config file. I really don't know where to start? How would you go about it? Thank you. Eric -- Dave Peterson |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
"Config file"
Hi Eric,
i use a siple textfile and import it into the addin like this: Sub read_Txt() Dim strfile As String Dim strTxtrow As String Open strfile For Input As #1 Do While Not EOF(1) Line Input #1, strTxtrow ' row for row inoput 'Your code for......... whatever you need Loop Close #1 End Sub hth Nobby "Eric" schrieb im Newsbeitrag ... Hi, I am writing an add-in and one of its first duty should be to be able to read a "config file" containing several settings necessary to the other procedures in the add-in. Another procedure in the add-in will also allow the user to change and save new settings into this same config file. I really don't know where to start? How would you go about it? Thank you. Eric |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
"Config file"
I would add to the other replies that you could/should save your settings
the System Registry instead of a text ini file. The registry was intended and designed to replace the ini files of yesteryear. Using the registry has the possible advantage that if there are two or more users of the same machine, each with his own logon id, each user will have their own configuration settings, rather than all users using the same config file, with one user overwriting another user's settings. For some simple code to work with the System Registry that wraps up all the Windows APIs into nice, neat, VBA-friendly procedures, see www.cpearson.com/excel/registry.htm . -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com (email address is on the web site) "Eric" wrote in message ... Hi, I am writing an add-in and one of its first duty should be to be able to read a "config file" containing several settings necessary to the other procedures in the add-in. Another procedure in the add-in will also allow the user to change and save new settings into this same config file. I really don't know where to start? How would you go about it? Thank you. Eric |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
"Config file"
"Chip Pearson" wrote in message ... Using the registry has the possible advantage that if there are two or more users of the same machine, each with his own logon id, each user will have their own configuration settings, rather than all users using the same config file, with one user overwriting another user's settings. Easily overcome by adding the users login name to the filename or as part of the key. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Converting "uppercase" string data to "lower case" in CSV file | Excel Discussion (Misc queries) | |||
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell | Excel Discussion (Misc queries) | |||
Lost "File Menu" - now it's "Edit / View / Insert.." but no "F | Excel Discussion (Misc queries) | |||
Problem- Recording macros for "file save" and "File open" | Excel Programming | |||
"Headroom" on <Files=99 in config.sys | Excel Programming |