VBA如何确定正在使用的应用程序

时间:2015-03-18 13:17:09

标签: vba excel-vba access-vba excel

我有一个在MS Access和MS Excel中使用的VBA功能。在MS Excel中使用时,我使用Application.Volatile,但是当它在MS Access中放置或使用时,它将无法编译。有没有办法让这条线路可以互换而不必在放入MS Access时将其删除?

谢谢你, 佛瑞德

2 个答案:

答案 0 :(得分:1)

您可以要求提供申请名称:

If Application.Name = "Microsoft Access" then
   'Do Nothing ......Or whatever you need to do.

ElseIf Application.Name = "Microsoft Excel" then
    Application.Run "Application.Volatile"
End If

答案 1 :(得分:1)

来自帮助。

Visual Basic for Applications参考

CallByName功能

执行对象的方法,或设置或返回对象的属性。

语法

CallByName(object, procname, calltype,[args()])

CallByName函数语法具有以下命名参数:

Part Description 
object Required; Variant (Object). The name of the object on which the function will be executed. 
procname Required; Variant (String). A string expression containing the name of a property or method of the object. 
calltype Required; Constant. A constant of type vbCallType representing the type of procedure being called. 
args() Optional: Variant (Array). 

<强>说明

CallByName函数用于获取或设置属性,或使用字符串名称在运行时调用方法。

在下面的示例中,第一行使用CallByName设置文本框的MousePointer属性,第二行使用MousePointer属性的值,第三行调用Move方法移动文本框:

CallByName Text1, "MousePointer", vbLet, vbCrosshair
Result = CallByName (Text1, "MousePointer", vbGet)
CallByName Text1, "Move", vbMethod, 100, 100

向MSDN发送反馈。请点击此处查看MSDN Online资源。

相关问题