Application.ExecuteExcel4Macro

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 - 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 "UNREGISTER(""MyAddin.xll"")"
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(register_id, argument [,argument2])
CALL(module_text, procedure, type_text, argument1 [,argument2])


register_id - The value returned from a REGISTER or REGISTER.ID function.
argument1 - The first argument to be passed to the procedure.
argument2 - (Optional) The second argument to be passed to the procedure.
module_text - The name of the DLL that contains the procedure (for Windows).
procedure - The name of the procedure in the DLL (for Windows).
type_text - The text string specifying the data type of the return value.


REMARKS
Removed in 2000.
Lets you call a dll function directly from a cell on an XLM sheet.
Allows you to point to a function defined in a dll and then call that from a worksheet cell.
To use this function you need to wrap an XLM and expose it as an XLM worksheet function.
Or you can use VBA to wrap the call. This function is case sensitive.
You can also use the ordinal value of the function from the EXPORTS statement in the module-definition file (.DEF) although this must not be in text format.
You can also use the resource ID number although this must not be in text format.
The "type_text" also lists the data types of all arguments to the DLL or code resource.
The first letter of type_text specifies the return value.
The "type_text" argument is not needed for stand-alone DLLs or code resources (XLLs).
You can have a maximum of ?? Arguments.
This Excel function cannot be called from VBA and there is no VBA equivalent.
If you are using a Macintosh then the function syntax is slightly different.
You can use the REGISTER function to return the registry ID for a specific DLL (dynamic linked library).
You can use the REGISTER.ID function to return the registry ID for a specific DLL.



REGISTER

The REGISTER.ID function can be used on worksheets (unlike REGISTER), but you cannot specify a function name and argument names with REGISTER.ID.



REGISTER.ID

REGISTER.ID(module_text, procedure [,type_text])
module_text - The name of the DLL that contains the procedure (for Windows).
procedure - The name of the procedure in the DLL (for Windows).
type_text - The text string specifying the data type of the return value.


This function was added to replace REGISTER
For an illustrated example refer to the page under Advanced Functions
This function can be used on worksheets (unlike REGISTER), but you cannot specify a function name and argument names with REGISTER.ID.


'=REGISTER.ID("Kernel32","GetTickCount")
'=REGISTER.ID("Kernel32","GetTickCount","K")
'=REGISTER.ID("Kernel32","GetTickCount","K")


https://support.office.com/en-us/article/register-id-function-f8f0af0f-fd66-4704-a0f2-87b27b175b50


This function does not appear in the 'Insert Function' dialog box.
This function can be used on worksheets (unlike REGISTER), but you cannot specify a function name and argument names with REGISTER.ID.
You can also use the ordinal value of the function from the EXPORTS statement in the module-definition file (.DEF) although this must not be in text format.
You can also use the resource ID number although this must not be in text format.
The first letter of "type_text" specifies the return value. If the function or code resource is already registered, you can omit this argument.
If you are using a Macintosh then the function syntax is slightly different REGISTER.ID(file_text, resource, type_text). file_text is the name of the file that contains the code resource. resource is the name of the procedure in the code resource.


Returns the register if for the function called MyFunction.
=REGISTER.ID("Kernel32","MyFunction")


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)
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)
CALL: This function allows you to call a registered function or command using its registration ID. The syntax for this function is: =CALL(register_id, argument1, argument2, ...)
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)


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext