macula 发表于 2005-8-11 20:19:00

[VBA]如何的到.dvb文件的路径?

<P>VBA中,一个函数如何获取它本身所在的.dvb文件的路径?</P>
<P>如函数:function aPath() as string&nbsp;&nbsp; 存在于 d:\bbb\a.dvb 文件中,</P>
<P>则aPath 函数返回 "d:\bbb"&nbsp; ?</P>

王咣生 发表于 2005-8-11 22:23:00

reply

<P>在AutoCAD2004下:</P>
<P>'取得当前应用程序路径<BR>Private Function GetDvbPath() As String<BR>&nbsp;&nbsp;&nbsp; On Error Resume Next<BR>&nbsp;&nbsp;&nbsp; Err.Clear<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim strFilePath As String<BR>&nbsp;&nbsp;&nbsp; Dim strFileName As String<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; strFileName = VBE.ActiveVBProject.FileName</P>
<P>&nbsp;&nbsp;&nbsp; If Err Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strFilePath = ""<BR>&nbsp;&nbsp;&nbsp; Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim pos As Integer<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pos = VBA.InStrRev(strFileName, "\", -1, vbTextCompare)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strFilePath = VBA.Left(strFileName, pos - 1)<BR>&nbsp;&nbsp;&nbsp; End If</P>
<P>&nbsp;&nbsp;&nbsp; GetDvbPath = strFilePath<BR>&nbsp;&nbsp;&nbsp; <BR>End Function</P>

macula 发表于 2005-8-14 17:58:00

明白了!多谢赐教!

sccat 发表于 2006-4-19 22:20:00

如果是lsp文件呢?
页: [1]
查看完整版本: [VBA]如何的到.dvb文件的路径?