Application.ExecuteExcel4Macro
Also known as XLM Macros
This registers the function only for that particular workbook.
Runs a Microsoft Excel 4.0 Macro function and then returns the result of the function.
The return type depends on the function called.
This function has no context associated with it so any references or names must be fully qualified and specified.
link - support.microsoft.com/en-us/office/working-with-excel-4-0-macros-ba8924d4-e157-4bb2-8d76-2c07ff02e0b8
link - outflank.nl/blog/2018/10/06/old-school-evil-excel-4-0-macros-xlm/
Running a Macro
This will only work if the workbook name is specified
Public Sub MyMacro()
Dim myreturn As Variant
myreturn = Application.ExecuteExcel4Macro("Book1!RunThis()")
End Sub
Public Sub RunThis()
MsgBox("hello")
End Sub
Position of a Cell
This returns the horizontal distance in points from the left edge of a cell to the left edge of the window
Application.ExecuteExcel4Macro "GET.CELL(42)"
This returns the horizontal distance in points from the right edge of a cell to the left edge of the window
Application.ExecuteExcel4Macro "GET.CELL(44)"
Calling a Worksheet Function
You could even use the following although this is not very common
x = Application.ExecuteExcel4Macro("Sqrt(4)")
Other Examples
If your string contains double quotes then you must use two double quotes in your text string
Application.ExecuteExcel4Macro "Get.ToolBar(7, ""Ribbon"")"
Application.ExecuteExcel4Macro "Show.ToolBar(""Ribbon"", False)"
Application.ExecuteExcel4Macro "GET.DOCUMENT(50)" - returns the number of pages to be printed
Application.ExecuteExcel4Macro "GET.WORKBOOK"
Application.ExecuteExcel4Macro "Evaluate"
On a Macro4 Worksheet
CallFunction
=RESULT(7)
=RETURN()
link - support.microsoft.com/en-us/office/using-the-call-and-register-functions-06fa83c1-2869-4a89-b665-7e63d188307f
link - support.microsoft.com/en-us/office/call-function-32d58445-e646-4ffd-8d5e-b45077a5e995
link - support.microsoft.com/en-us/office/register-id-function-f8f0af0f-fd66-4704-a0f2-87b27b175b50
CALL
CALL - This function allows you to call a registered function or command using its registration ID.
CALL(register_id, argument [,argument2])
REGISTER.ID
REGISTER.ID - The result after running an Excel 4.0 Macro function.
REGISTER.ID(module_text, procedure [,type_text])
GET.WORKSPACE
This function returns information about the current Excel workspace, such as the number of open workbooks or the available memory.
The syntax for this function is: =GET.WORKSPACE(info_type)
INFO
This function returns information about the current Excel environment, such as the operating system or the Excel version.
The syntax for this function is: =INFO(info_type)
REGISTER
REGISTER: This function is similar to REGISTER.ID but returns a reference to the registered function or command instead of its registration ID. The syntax for this function is: =REGISTER(module_text, procedure, type_text, function_text, argument_text)
The REGISTER.ID function can be used on worksheets (unlike REGISTER), but you cannot specify a function name and argument names with REGISTER.ID.
Application.ExecuteExcel4Macro "REGISTER(""MyAddin.xll"")"
UNREGISTER
This function allows you to unregister a custom function or command using its registration ID. The syntax for this function is: =UNREGISTER(register_id)
Application.ExecuteExcel4Macro "UNREGISTER(""MyAddin.xll"")"
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext