With Analytics Edge Add-in, you can run an Analytics Edge macro (e.g. “MyMacro”) from Visual Basic for Applications (VBA), using code similar to the following:
Dim a As Variant a = Application.Run("AnalyticsEdge.RunMacro", "MyMacro") ThisWorkbook.Worksheets("Sheet1").Range("A1").Value = CStr(a)
If you want to refresh all queries and macros in another workbook, activate the other workbook and call “RefreshAll”:
Dim a As Variant Workbooks.Open("C:\Users\Mike\Documents\test1.xlsx").Activate a = Application.Run("AnalyticsEdge.RunMacro", "RefreshAll", "true") ThisWorkbook.Worksheets("Sheet1").Range("A1").Value = CStr(a)
Note that you can also run VBA macros from Analytics Edge macros as well:
See Using the Run Macro Function
Syntax:
Application.Run("AnalyticsEdge.RunMacro", <macroName>[, <runSilent>]) where <macroName> is the name of the macro, or "RefreshAll" and optional <runSilent> is "true" to suppress any popup messages
Programming Notes:
- If you choose to run silent (suppressing popups), then write the results to a worksheet cell so you are aware of any errors
- In most cases, the call will return a string, but some error conditions may return a non-string, so it is best to treat the value as a Variant
- If refreshing another workbook, make sure to Activate that workbook before calling the macro