Option Explicit
Const cstrPathIni = "C:\Junk\MyExcelSettings.ini"
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
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
'**************************************************************************
'Procedure: ProfileSettingSave
'Purpose: Set user profile setting in initialization file.
'Inputs: v_strKey: Key for value in ini file.
' v_strSetting: Value to assign to key.
'Requires: WritePrivateProfileString | API
'Notes: Name for section is "ExcelData".
' Path for ini file is cstrPathIni.
'**************************************************************************
Public Sub ProfileSettingSave(ByVal v_strKey As String, ByVal v_strSetting As String)
WritePrivateProfileString "ExcelData", v_strKey, v_strSetting, cstrPathIni
End Sub
'**************************************************************************
'Procedure: ProfileSettingGet
'Purpose: Get user profile setting from initialization file.
'Inputs: v_strKey: Key for value in ini file.
' v_strDefault: Default value for setting (optional).
'Returns: Setting if found, Default if not found.
'Requires: GetPrivateProfileString | API
'Notes: Name for section is "ExcelData".
' Path for ini file is cstrPathIni.
'**************************************************************************
Public Function ProfileSettingGet(ByVal v_strKey As String, _
Optional ByVal v_strDefault As String = vbNullString) _
As String
Dim strSetting As String * 255 ' String buffer to accept setting value.
ProfileSettingGet = Left$(strSetting, _
GetPrivateProfileString("ExcelData", v_strKey, _
v_strDefault, strSetting, 255, cstrPathIni))
End Function
Sub InYourVBApp()
ProfileSettingSave "Check1Name", "First Check Box"
ProfileSettingSave "Check1Value", 1
End Sub
Sub InExcel()
Sheets(1).CheckBox1.Caption = ProfileSettingGet("Check1Name", "CheckBox1")
Sheets(1).CheckBox1.Value = ProfileSettingGet("Check1Value", 0)
End Sub