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