Multiple excel server problem
-
I am running 2 excel files on my system . there are 2 excel.exe(server) showing in the process tab of taskmanager .when I called GetActiveObject() function I always get the pointer of same excel . never get of another excel file . how can I get the object of every excel server running in the process
Trioum
-
I am running 2 excel files on my system . there are 2 excel.exe(server) showing in the process tab of taskmanager .when I called GetActiveObject() function I always get the pointer of same excel . never get of another excel file . how can I get the object of every excel server running in the process
Trioum
http://support.microsoft.com/kb/238975 Office applications typically registers their the first instance only in the ROT. but they are supposed to register their individual documents in the ROT, so iterating through the ROT using IRunningObjectTable Interface may be the option to get the instance you want, provided you know the document which is opened with that instance.
-
http://support.microsoft.com/kb/238975 Office applications typically registers their the first instance only in the ROT. but they are supposed to register their individual documents in the ROT, so iterating through the ROT using IRunningObjectTable Interface may be the option to get the instance you want, provided you know the document which is opened with that instance.
-
eventhough multple instances of excel are running, only the first instance would have an entry in ROT. But all the instances registers the documents opened in them in ROT. Its the key to bind to that instance of excel. say, u have more than one instances of excel apps, and want to get the instance in which "MyExcel.xls" file is opened..
void GetMyExcelInstance()
{
CApplication oExcelApp; //class wizard generated class for excel appCoInitialize(NULL); HRESULT hr; //Setup ROT IBindCtx \*piBindCtx = 0; hr = CreateBindCtx( 0, &piBindCtx ); IRunningObjectTable \*piROT = 0; hr = piBindCtx->GetRunningObjectTable(&piROT); //Enumerate registered objects IEnumMoniker \*piEnum = 0; hr = piROT->EnumRunning(&piEnum); piEnum->Reset(); ULONG nFetched; IMoniker \*piMoniker = 0; bool bGot = false; while(piEnum->Next(1, &piMoniker, &nFetched) == S\_OK && !bGot) { // Get Display name, in our case can be the workbook (excel doc) name LPOLESTR strName; hr = piMoniker->GetDisplayName(piBindCtx, NULL, &strName); CString csName(strName); CoTaskMemFree(strName); if(csName.Find(L"MyExcel.xls") != -1) //or you may compare against full path of MyExcel.xls file { //Bind to the object. In this case object is excel workbook. IDispatch \*piDispObj = 0; hr = piMoniker->BindToObject(piBindCtx, NULL, IID\_IDispatch, (void\*\*)&piDispObj); CWorkbook oWorkBook(piDispObj); //class for excel workbook object oExcelApp = oWorkBook.get\_Application(); bGot = true; } piMoniker->Release(); } piEnum->Release(); piROT->Release(); piBindCtx->Release(); if(bGot) { //do here with oExcelApp }
}
do proper error checking.. :thumbsup:
-
eventhough multple instances of excel are running, only the first instance would have an entry in ROT. But all the instances registers the documents opened in them in ROT. Its the key to bind to that instance of excel. say, u have more than one instances of excel apps, and want to get the instance in which "MyExcel.xls" file is opened..
void GetMyExcelInstance()
{
CApplication oExcelApp; //class wizard generated class for excel appCoInitialize(NULL); HRESULT hr; //Setup ROT IBindCtx \*piBindCtx = 0; hr = CreateBindCtx( 0, &piBindCtx ); IRunningObjectTable \*piROT = 0; hr = piBindCtx->GetRunningObjectTable(&piROT); //Enumerate registered objects IEnumMoniker \*piEnum = 0; hr = piROT->EnumRunning(&piEnum); piEnum->Reset(); ULONG nFetched; IMoniker \*piMoniker = 0; bool bGot = false; while(piEnum->Next(1, &piMoniker, &nFetched) == S\_OK && !bGot) { // Get Display name, in our case can be the workbook (excel doc) name LPOLESTR strName; hr = piMoniker->GetDisplayName(piBindCtx, NULL, &strName); CString csName(strName); CoTaskMemFree(strName); if(csName.Find(L"MyExcel.xls") != -1) //or you may compare against full path of MyExcel.xls file { //Bind to the object. In this case object is excel workbook. IDispatch \*piDispObj = 0; hr = piMoniker->BindToObject(piBindCtx, NULL, IID\_IDispatch, (void\*\*)&piDispObj); CWorkbook oWorkBook(piDispObj); //class for excel workbook object oExcelApp = oWorkBook.get\_Application(); bGot = true; } piMoniker->Release(); } piEnum->Release(); piROT->Release(); piBindCtx->Release(); if(bGot) { //do here with oExcelApp }
}
do proper error checking.. :thumbsup:
-
//code is ok up to here CWorkbook oWorkBook(piDispObj); //class for excel workbook object // but as I called the following line errro occurs member not found oExcelApp = oWorkBook.get_Application();
Trioum
did you generate wrapper classs for excel type library? those class members may vary in different visual studio versions. check your class for WorkBook object to see how it returns Application object. it may be by get_Application() or GetApplication() or by some other means...