How to run a macro vba Excel using automation from C++

  • Thread starter Thread starter Juan David Ramirez Vasquez
  • Start date Start date
J

Juan David Ramirez Vasquez

Guest
Hello Friends,

I need a little help

I'm develop a dll that connect with Excel, for this I use a AutoWrap funtion (How to automate Excel from C++ without using MFC or - Office). I can already open the excel file and write data into the cells, but now i need run a macro. I'm using the next code:

VARIANT res;
VariantInit(&res);
VARIANT methodName;
VariantInit(&methodName);
methodName.bstrVal = CharToBSTR("All_combined");//CharToBSTR function it's mine
hr = AutoWrap(DISPATCH_METHOD, &res, pXlApp, L"Run", 1,methodName);

BSTR CharToBSTR(char* cadena) {
int wslen = MultiByteToWideChar(CP_ACP, 0, cadena, strlen(cadena), 0, 0);
BSTR bstr = SysAllocStringLen(0, wslen);
MultiByteToWideChar(CP_ACP, 0, cadena, strlen(cadena), bstr, wslen);
return bstr;
}

Now, this code does not throw an error, but neither run the macro!

I don't know where are my error

Thank you for your replies,

Continue reading...
 
Back
Top