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 strAppName As String, _
ByVal strKeyName As String, _
ByVal strKeyDefault As String, _
ByVal strFileName As String)
Sub Zet_ini_waarde_over()
'// verander hier je foldermap, de sectieverwizing in je ini file en je key verwijzing in je ini file.
Range("a1") = GetKeyVal("C:\EXCEL\test.ini", "HOST", "NoDriver")
End Sub
Function GetKeyVal(ByVal IniFile As String, ByVal Section As String, ByVal Key As String)
Dim RetVal As String, Exec As Integer, GetIni As String
'// Retrieve info from an INI File
'// IniFile = The location of the INI File (eg. "C:WindowsINIFile.ini")
'// [Section] = [Section] where the Key is held
'// Key = The Key of which you want to retrieve information
'// Check to see if the INI File specified exists
'// If you wish then change code to create File
FileExists IniFile
'// If INI File exists then proceed to Get Key Value
'// Create a buffer to hold the string
RetVal = String(255, 0)
'// Exercute the call and get the string len
Exec = GetPrivateProfileString(Section, Key, "", RetVal, Len(RetVal), IniFile)
If Len(Exec) = 0 Then
GetKeyVal = ""
Else
GetKeyVal = Left(RetVal, InStr(RetVal, Chr(0)) - 1)
End If
End Function
Function FileExists(FullFilePath As String)
If Dir(FullFilePath) = "" Then
MsgBox "File Not Found: " & FullFilePath & vbCrLf & _
"Please check the Path name!", vbExclamation, "INI File Not Found"
'//Note: Use of End - Lets end it here !
End
End If
End Function