VBA读取ini配置相对应的内容

发布时间 2023-10-07 17:30:56作者: sonycat
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer

Function GetIni(KeyStr As String, Wat As String, ByVal Fil As String) As String
    Dim n As Integer
    Dim KeyValue As String
    KeyValue = Space(255)
    n = GetPrivateProfileString(KeyStr, Wat, "", KeyValue, 255, Fil)
    If n > 0 Then
        KeyValue = WorksheetFunction.Clean(Trim(KeyValue))
    Else
        KeyValue = ""
    End If
    GetIni = KeyValue
End Function