首先,我是一个Excel宏的新手。 我最近阅读了一些文章并进行了一些工作。但现在我很犹豫。能否将.txt或.xml文件放入VBAProject中?如果可以,如何放置以及如何获取文件路径或只是读取该文件?如果不行,是否有过渡方法来完成这项工作?只考虑宏,而非AddIn项目。 非常感谢!
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 Long, ByVal lpFileName As String) As Long
Public Function GetINIString(ByVal sApp As String, ByVal sKey As String, ByVal filepath As String) As String
Dim sBuf As String * 256
Dim lBuf As Long
lBuf = GetPrivateProfileString(sApp, sKey, "", sBuf, Len(sBuf), filepath)
GetINIString = Left$(sBuf, lBuf)
End Function
Sub sample()
Dim Path As String
Path = ThisWorkbook.Path & "\" & "Path.ini"
Link = GetINIString("Path", "Link", Path)
End Sub
Path
变量。请注意保留HTML标记。