[求助]VBA怎么获取自己的路径?
VB可用App.Path可以获取自己的路径,请问VBA的代码是什么呢? 转贴:'取得当前应用程序路径
Private Function GetDvbPath() As String
On Error Resume Next
Err.Clear
Dim strFilePath As String
Dim strFileName As String
strFileName = VBE.ActiveVBProject.FileName
If Err Then
strFilePath = ""
Else
Dim pos As Integer
pos = VBA.InStrRev(strFileName, "\\", -1, vbTextCompare)
strFilePath = VBA.Left(strFileName, pos - 1)
End If
GetDvbPath = strFilePath
End Function
非常感谢版主 学习了。 我试了怎么不好用 Private Function GetDvbPath() As String
On Error Resume Next
Err.Clear
Dim strFilePath As String
Dim strFileName As String
strFileName = ThisDrawing.VBE.ActiveVBProject.FileName
If Err Then
strFilePath = ""
Else
Dim pos As Integer
pos = VBA.InStrRev(strFileName, "\", -1, vbTextCompare)
strFilePath = VBA.Left(strFileName, pos - 1)
End If
GetDvbPath = strFilePath
End Function
我作了点改动,在VBA里通过了测试。返回的路径类似:C:\aaa\bbb
少写了一点,是ThisDrawing.Application.VBE.ActiveVBProject.FileName
页:
[1]