Private Sub TiaoNo1(EXEName1 As String)
On Error GoTo Meiyoufaxian
'NAME为“1.exe”这样的形式
'调用根目录下的某个可执行程序
Dim Zhuangtai As Boolean
'定义标志位,如果检测到目标程序就置TRUE
Dim Lujiang As String
'定义路径
Dim Panfu As Long
Panfu = 67
'初始化盘符为C盘
Zhuangtai = False
'初始化状态
Do While Zhuangtai = False
If Panfu > 89 Then Exit Do
lujing = Chr(Panfu) & ":\" & EXEName1
If Dir(lujing) = "" Then
Panfu = Panfu + 1
Else
Zhuangtai = True
End If
Loop
MsgBox lujing, , "发现目标路径:"
If Zhuangtai = True Then Shell lujing, vbNormalFocus
'具体要隐藏执行还是正常执行你就自己改
Exit Sub
Meiyoufaxian:
If Err.Number = 52 Then
MsgBox "程序不存在", , "提示"
Else
MsgBox "程序无法调用,请检查", , "提示"
End If
End Sub
Private Sub TiaoNo2(EXEName2 As String)
'NAME2为“1.exe”这样的形式
'调用同级目录下的某个可执行程序
Dim Lujin2 As String
Lujin2 = App.Path & "\" & EXEName2
If Dir(Lujin2) <> "" Then
Shell Lujin2, vbNormalFocus
Else
MsgBox "程序不存在", , "提示"
End If
End Sub
Private Sub Command1_Click()
TiaoNo1 ("1.exe") '调用C或者D或者E等盘符下的某一个1.exe程序
End Sub
Private Sub Command2_Click()
TiaoNo2 ("2.exe") '调用同个目录下的2.exe
End Sub