[英]VBA how to determine which application is being used
我有一個在 MS Access 和 MS Excel 中使用的 VBA 函數。 在 MS Excel 中使用時,我使用 Application.Volatile,但在 MS Access 中放置或使用它時,它不會編譯。 有沒有辦法讓這條線在放置在 MS Access 中時可以互換而不必刪除它?
謝謝你,弗雷德
您可以詢問應用程序的名稱:
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
從幫助。
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 資源。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.