VBA中没有App对象。在Visual Basic 6.0(VB6)中,App是一个全局对象,可以通过App关键字直接访问,用于获取当前应用的标题、版本、路径、执行文件名等信息,并判断应用的前一个实例是否运行。然而,在Visual Basic .NET(VB.NET)中,App对象已经不存在了。
那么用代码就可以判断在哪里运行了。
在VB6中可以,新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Function f_IsVB6() As Boolean
On Error GoTo hErr
Dim strTemp As String
strTemp = App.Path
f_IsVB6 = True
Exit Function
hErr:
f_IsVB6 = False
End Function
Private Sub Command1_click()
Dim strIsVB6 As String
strIsVB6 = f_IsVB6
MsgBox strIsVB6
End Sub
以上代码在Office 的 Excel 的 Visual Basic 中也可以运行,对于写VB插件的朋友来说这种方式很智能。