Option Explicit
Private Declare Function PathFileExists Lib "shlwapi.dll" Alias "PathFileExistsA" (ByVal pszPath As String) As Long
Sub C100()
Dim s As String
Dim ss As String
s = Dir("c:xzh.txt")
Do While Len(s)
ss = "g:" & s
If PathFileExists(ss) Then
MsgBox "g盘上有" & s
End If
s = Dir
Loop
End Sub
以上是VBA代码
在C盘跟G盘根目录下面创建一个 xzh.txt文件 然后加载这个vba程序运行是可以得到运行结果的。