View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Lynn McGuire[_3_] Lynn McGuire[_3_] is offline
external usenet poster
 
Posts: 7
Default executing VBA macro in Excel from OLE

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.

Thanks,
Lynn


BTW, I am using the C++ code from
http://support.microsoft.com/kb/216686

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);

Thanks,
Lynn