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
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
On a Macro4 Worksheet
CallFunction
=RESULT(7)
=CALL("Kernel32","GetTickCount","J!")
=RETURN()
© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext