Vba excel application run

This can be used to run a macro written in Visual Basic or the Microsoft Excel macro language, or to run a function in a DLL or XLL.

You cannot use named arguments with this method. Arguments must be passed by position.
You must pass all the parameters as separate arguments and not as one single string (for example Application.Run("Macro(Arg1,Arg2,Arg3)")

If the datatype of any of your paramaters (or of the returned datatype) is not declared then these items are assumed to have the Variant datatype.
All the arguments are converted to values which means you cannot pass any objects
Any objects passed as arguments to a macro will be converted to a value (by applying the Value property to the object).

Calling Procedure in a different file

This can be done in two ways.
1) Create a reference to the other file. To create a reference (Tools > References).
After a reference has been established you can call procedures in other files.
The referenced file does not have to be open and is treated like an object library.
2) Use the Application.Run method and specify the filename and folder path of the other file.

Calling Procedure assigned to a Variable

Calling Function assigned to a Variable (with Arguments)

It is possible to use Application.Run to return a value from a function.
Exactly the same thing can be achieved by using a subroutine and a ByRef argument.

If you want to call a Function that has a return value you can use the GetMemoryAddress API function.

Читайте также:  7838 М сколько км и м

Runs a Visual Basic macro.
You can pass up to 30 parameter values to the specified macro.
If you specify the document name, your code can only run macros in documents related to the current context, not just any macro in any document.

This assumes the VBA Project has been changed to MyProject. This is rarely changed.

Include an example with a folder location as well !!
Although Visual Basic code can call a macro directly (without this method being used), this method is useful when the macro name is stored in a variable (for more information, see the example for this topic).
The following statements are functionally equivalent.

How can I use Application.Run with named arguments? Based on this MS documentation:

You cannot use named arguments with this method. Arguments must be passed by position.

The solution to force argument passing by position might seem a bit inflexible for my code purpose, which is to create a macro that runs other people’s macro by passing some arguments. Example as below:

My question is similar to this but there it does not answer my question. So how can I find the alternative for Application.Run ?

Scenarios/Assumptions

I have my own macro. At the same time, I’m using other people’s macro (from add-in for example). Both of us have no communication, nor have a proper documentation for the addin. The potential scenarios are as below (2):

The addin code is fixed

  • I know that I have to pass foo and bar but unknown the order. I cannot open the code bcs the macro is password protected, for example.
Читайте также:  Xerox phaser 3110 драйвер для windows 10

My code is fixed

  • Somebody else is using my macro. They know that when they use my macro, they have to accept the two arguments foo and bar but unknown position.
  • My macro is password protected.
  • This case is easier since I can at least do my part and create a proper documentation.

My actual situation is more to number 2, so I think my solution now is just pass the arguments by position, and create a proper documentation for it. But I am just testing out the situation number 1, if maybe somebody has encountered it before or have any idea to resolve it?

Запускает макрос или вызывает функцию. Runs a macro or calls a function. Это можно использовать для запуска макроса, написанного на языке Visual Basic или Microsoft Excel, или для запуска функции в библиотеке DLL или XLL. This can be used to run a macro written in Visual Basic or the Microsoft Excel macro language, or to run a function in a DLL or XLL.

Синтаксис Syntax

выражение: переменная, представляющая объект Application. expression A variable that represents an Application object.

Параметры Parameters

Имя Name Обязательный или необязательный Required/Optional Тип данных Data type Описание Description
Macro Macro Необязательный Optional Variant Variant Запускаемый макрос. The macro to run.

Это может быть строка с именем макроса, объект Range , указывающий, где находится функция, или идентификатор регистра для зарегистрированной функции DLL (XLL). This can be either a string with the macro name, a Range object indicating where the function is, or a register ID for a registered DLL (XLL) function.

Если используется строка, строка будет оцениваться в контексте активного листа. If a string is used, the string will be evaluated in the context of the active sheet.

Читайте также:  Smart screen off android
Arg1Arg30 Arg1Arg30 Необязательный Optional Variant Variant Аргумент, который должен быть передан в функцию. An argument that should be passed to the function.

Возвращаемое значение Return value

Примечания Remarks

С этим методом нельзя использовать именованные аргументы. You cannot use named arguments with this method. Аргументы должны передаваться по положению. Arguments must be passed by position.

Метод Run возвращает все возвращаемые вызываемые макросы. The Run method returns whatever the called macro returns.

Поддержка и обратная связь Support and feedback

Есть вопросы или отзывы, касающиеся Office VBA или этой статьи? Have questions or feedback about Office VBA or this documentation? Руководство по другим способам получения поддержки и отправки отзывов см. в статье Поддержка Office VBA и обратная связь. Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.

Rate this post

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *