用这个吧,更简单些。Option Explicit Private Declare Function GetModuleFileName Lib "kernel32.dll" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As LongPrivate Function AppExeName() As String Dim strFileName As String Dim lngCount As Long strFileName = String(255, 0) lngCount = GetModuleFileName(App.hInstance, strFileName, 255) AppExeName = Left(strFileName, lngCount) End Function
Private Declare Function GetModuleFileName Lib "kernel32.dll" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As LongPrivate Function AppExeName() As String
Dim strFileName As String
Dim lngCount As Long
strFileName = String(255, 0)
lngCount = GetModuleFileName(App.hInstance, strFileName, 255)
AppExeName = Left(strFileName, lngCount)
End Function
这样子就可以了