View Single Post
  #4   Report Post  
Old March 26th 19, 08:01 PM posted to microsoft.public.excel.programming
Adrian Caspersz Adrian Caspersz is offline
external usenet poster
First recorded activity by ExcelBanter: Sep 2016
Posts: 10
Default executing VBA macro in Excel from OLE

On 26/03/2019 18:46, Lynn McGuire wrote:
On 3/26/2019 12:47 PM, Lynn McGuire wrote:
How does one execute a VBA macro in Excel from OLE ?* I cannot get the
C++ code to work.


BTW, I am using the C++ code from

I am calling AutoWrap with name of the VBA macro in the
visualBasicMacroName string.* I am getting an error that the
pDisp-GetIDsOfNames call in AutoWrap is not finding the VBA method.

****VARIANT result1;
****VariantInit ( & result1);
****std::string errorMsg = "Executing Visual Basic Macro, " +
visualBasicMacroName + " (ExecuteVisualBasicMacro)";
****WCHAR methodName [1000];
****charToWchar (visualBasicMacroName.c_str (), methodName, sizeof
(methodName) / sizeof (WCHAR));
****AutoWrap (DISPATCH_METHOD, & result1, pExcelWorkbooks, methodName,
errorMsg, 0);

Is the VBA method in a 'module', i.e. not a sheet.

As a visibility test, can you call it from somewhere else, say PowerShell?

FWIW, these days I'm a fan of controlling Excel from PowerShell instead
of VBA[1] inside, as I can reach out to a lot more connected systems.
That C++ looks scary, unless you have other reasons for being in that

[1] event handlers being an exception.

Adrian C