How to get IDispatch of an instance of Excel in C++ DLL called from Excel xla?
-
Hi I have created a c++ dll which works great in excel 2000, as I launch it as a com add-in, and get access to the IDispatch of the calling instance of excel via OnConnection (IDTExtensibility2). I would like to be able to launch the dll from excel 97, via an xla (or xll), which is not a problem, but I do not know how to get the IDispatch of the instance of excel that has the xla (or xll) running. (Excel.Application is no good, as it only finds the first instance of Excel.) If anyone knows the answer, please let me know Thanks!
-
Hi I have created a c++ dll which works great in excel 2000, as I launch it as a com add-in, and get access to the IDispatch of the calling instance of excel via OnConnection (IDTExtensibility2). I would like to be able to launch the dll from excel 97, via an xla (or xll), which is not a problem, but I do not know how to get the IDispatch of the instance of excel that has the xla (or xll) running. (Excel.Application is no good, as it only finds the first instance of Excel.) If anyone knows the answer, please let me know Thanks!
Hi I have worked out how to do it from an xla , but if anyone knows how to do the same in an xll please let me know. From Auto_Open() sub of xla, pass Application to function in DLL i.e. in XLA !declaration of function in DLL Private Declare Function InitExcel97 Lib "MyDLL.dll" (ByVal app As Object) As Long Public Sub Auto_Open() Result = InitExcel97(Application) … End Sub in DLL extern "C" __declspec( dllexport ) LONG WINAPI InitExcel97(LPDISPATCH Application) { long result; g_pApplication = Application; //global declaration IDispatch* g_pApplication; theApp.InitializeExcel(); //calls same code as if launched by com addin in Excel2000 …. return result; }
-
Hi I have created a c++ dll which works great in excel 2000, as I launch it as a com add-in, and get access to the IDispatch of the calling instance of excel via OnConnection (IDTExtensibility2). I would like to be able to launch the dll from excel 97, via an xla (or xll), which is not a problem, but I do not know how to get the IDispatch of the instance of excel that has the xla (or xll) running. (Excel.Application is no good, as it only finds the first instance of Excel.) If anyone knows the answer, please let me know Thanks!
-
Hi, Those examples do not relate to my question, for each example creates its own instance of excel, which it then uses. I want to attach to an existing instance, and using AttachDispatch with Excel.Application, is no solution as it will only find the first instance of excel. As I mentioned in my prior message, it is easy from a xla, but I would still be curious how to find the correct IDistatch from an xll (or any c++ written application). For your information, a much better method than proposed in Q192348 is Q186427. The closest MSDN example to my problem is found in Q190985, but there, Excel is running as a container. Regards Leo