简体   繁体   English

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

[英]VBA how to determine which application is being used

I have a VBA function I use in MS Access and MS Excel.我有一个在 MS Access 和 MS Excel 中使用的 VBA 函数。 When used in MS Excel I use Application.Volatile but when it is placed or used in MS Access it will not compile.在 MS Excel 中使用时,我使用 Application.Volatile,但在 MS Access 中放置或使用它时,它不会编译。 Is there a way to make this line interchangeable without having to delete it when placed in MS Access?有没有办法让这条线在放置在 MS Access 中时可以互换而不必删除它?

Thank you, Fred谢谢你,弗雷德

You can ask for the name of the application:您可以询问应用程序的名称:

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

From Help.从帮助。

Visual Basic for Applications Reference Visual Basic for Applications 参考

CallByName Function CallByName 函数

Executes a method of an object, or sets or returns a property of an object.执行对象的方法,或设置或返回对象的属性。

Syntax句法

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

The CallByName function syntax has these named arguments: 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). 

Remarks评论

The CallByName function is used to get or set a property, or invoke a method at run time using a string name. CallByName 函数用于获取或设置属性,或在运行时使用字符串名称调用方法。

In the following example, the first line uses CallByName to set the MousePointer property of a text box, the second line gets the value of the MousePointer property, and the third line invokes the Move method to move the text box:在下面的示例中,第一行使用 CallByName 设置文本框的 MousePointer 属性,第二行获取 MousePointer 属性的值,第三行调用 Move 方法移动文本框:

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

Send feedback to MSDN.Look here for MSDN Online resources.向 MSDN 发送反馈。在此处查看 MSDN Online 资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM