[求助]如何用vba获取指定的搜索路径
我想得到我添加的搜索文件路径,不知用vba如何实现,谢谢指导! <FONT face=宋体 size=2>对于上面的问题,我想到了一个变通的办法,在本人电脑上均没问题,可一换就有问题!</FONT><FONT face=宋体 size=2>由于我是用vba调用外部块,每次安装到不同的电脑,外部块的绝对路径都要改变,我想请问一下如果获得dvb文件的路径,这样的话就可以方便的获得外部块的绝对路径了。<BR>看来没有人遇到过这个问题,我想了个解决办法:<BR>Dim oVbe As Object <BR>Dim aa As Variant <BR>Dim bb As String<BR>Dim a As Integer<BR>Dim b As Integer<BR>Dim c As Integer<BR>Set oVbe = Application.VBE<BR>aa = oVbe.VBProjects(1).FileName '获得当前dvb文件路径及文件名<BR>a = Len(aa) '获得全部路径的字段长度<BR>bb = "jingtong.dvb" '定义当前文件的名称<BR>b = Len(bb) '获得当前文件名的字段长度<BR>c = a - b '用全部字段长减去文件名字段长度<BR>Dim aaa As String<BR>aaa = Left(aa, c) '获得当前dvb文件存放的路径<BR>我的这个方法自己认为不好,因为我在2002,2004,2005上测试时均能通过,但是当换了一台电脑后就又出现调用外部块无法找到路径的问题!哪位高手有好的办法还麻烦告知,谢谢了!</FONT> 以下程序可以得到每一个支持文件搜索路径.
Sub FindSupportPath()<BR>Dim curSupportPath As Variant<BR>Dim i As Integer
curSupportPath = StoDim(ThisDrawing.Application.Preferences.Files, ";")
For i = 0 To UBound(curSupportPath)<BR> MsgBox curSupportPath(i)<BR>Next
End Sub
Function StoDim(ByVal s As String, Optional div As String) As Variant<BR>Dim s_len As Integer '字符串长度<BR>Dim s_p As Integer '查找开始位置<BR>Dim gs() As String<BR>Dim i As Integer<BR>Dim j As Integer
If div = "" Then div = " "
i = 0
s_p = 1
s = LTrim(s + div)<BR>s_len = Len(s)
j = 0<BR>While s_p <= s_len '找到最后子串<BR> If Mid(s, s_p, 1) = div Then '如果找到分隔符<BR> '取子字符串<BR> If s_p > 1 Then<BR> ReDim Preserve gs(j)<BR> gs(j) = Left(s, s_p - 1)<BR> j = j + 1<BR> End If<BR> s = LTrim(Right(s, s_len - s_p))<BR> s_len = Len(s) '替换后新串长度<BR> s_p = 1 '下次开始查找的位置<BR> i = i + 1<BR> Else<BR> s_p = s_p + 1 '如果没有找分隔符,从下一个开始<BR> End If<BR>Wend
'空数组<BR>If j = 0 Then Exit Function
StoDim = gs '得到字符串数组
End Function
页:
[1]