Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default What Name for GetIDsOfName() ?

Hi all,

I am trying to automate an Excel sheet from a Windows Froms
application. In a first step, I would like to be able to read/write in
cells. I know it has been done millions of times, I have read a lot of
things in newsgroups, and in msdn, but I am stuck here. GetIDsOfName
always return -1. I don't know what name I should give it ? Would help
me to go further ?

Thank you in advance,

AG.


IRunningObjectTable * prot;
IEnumMoniker * penumMoniker=NULL;
IUnknown * punkObject;
IMoniker * mon;
ULONG Fetched=0;
HRESULT hr;
if(GetRunningObjectTable(0,&prot)!=S_OK)
{
toolStripStatusLabel1-Text = "Error, could not get a pointer
on ROT";
return;


}


toolStripStatusLabel1-Text = "ROT OK";

if(prot-EnumRunning(&penumMoniker)!=S_OK)
{
toolStripStatusLabel1-Text = "Error, could not Enumerate
through the ROT";
return;



}


penumMoniker-Reset();

while(penumMoniker-Next(1,&mon,&Fetched)==S_OK)
{
IBindCtx * pCtx;
if(CreateBindCtx(0,&pCtx)!=S_OK)
{
toolStripStatusLabel1-Text = "Error, Could not Bind
Ctx";
return;
}
LPOLESTR Name;
for(int i=0;i<Fetched;i++)
{
// here the Name variable shows the path to my excel
sheet : "file://C:\test\testExcel.xls"
if(mon[i].GetDisplayName(pCtx,NULL,&Name)!=S_OK)
{
toolStripStatusLabel1-Text = "Error in
GetDisplayName";
}
}
pCtx-Release();


hr = prot-GetObject(&mon[0],&punkObject);
if(!FAILED(hr))
{
hr = prot-IsRunning(&mon[0]);
if(!FAILED(hr))
{
break;
}
}


}


IDispatch * pDisp;
hr = punkObject-QueryInterface(IID_IDispatch,(void**)&pDisp);
if(FAILED(hr))
{
toolStripStatusLabel1-Text = "Error querying the Interface";


}


DISPID id;
LPOLESTR Name=L"Excel";
hr = pDisp-GetIDsOfNames(IID_NULL,&Name,1,LOCALE_USER_DEFAUL T,&id);
if(FAILED(hr))
{
// I always get here. I am not sure the Name "Excel" is
correct or what to put here ? "Excel.Application" ,...?
toolStripStatusLabel1-Text = "GetIDsOfNames failed";
}

pDisp-Invoke(...)

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default What Name for GetIDsOfName() ?

On 8 nov, 14:14, AG wrote:[i]
Hi all,

I am trying to automate an Excel sheet from a Windows Froms
application. In a first step, I would like to be able to read/write in
cells. I know it has been done millions of times, I have read a lot of
things in newsgroups, and in msdn, but I am stuck here. GetIDsOfName
always return -1. I don't know what name I should give it ? Would help
me to go further ?

Thank you in advance,

AG.

IRunningObjectTable * prot;
IEnumMoniker * penumMoniker=NULL;
IUnknown * punkObject;
IMoniker * mon;
ULONG Fetched=0;
HRESULT hr;
if(GetRunningObjectTable(0,&prot)!=S_OK)
{
toolStripStatusLabel1-Text = "Error, could not get a pointer
on ROT";
return;

}

toolStripStatusLabel1-Text = "ROT OK";

if(prot-EnumRunning(&penumMoniker)!=S_OK)
{
toolStripStatusLabel1-Text = "Error, could not Enumerate
through the ROT";
return;

}

penumMoniker-Reset();

while(penumMoniker-Next(1,&mon,&Fetched)==S_OK)
{
IBindCtx * pCtx;
if(CreateBindCtx(0,&pCtx)!=S_OK)
{
toolStripStatusLabel1-Text = "Error, Could not Bind
Ctx";
return;
}
LPOLESTR Name;
for(int i=0;i<Fetched;i++)
{
// here the Name variable shows the path to my excel
sheet : "file://C:\test\testExcel.xls"
if(mon.GetDisplayName(pCtx,NULL,&Name)!=S_OK)
{
toolStripStatusLabel1-Text = "Error in
GetDisplayName";
}
}
pCtx-Release();

hr = prot-GetObject(&mon[0],&punkObject);
if(!FAILED(hr))
{
hr = prot-IsRunning(&mon[0]);
if(!FAILED(hr))
{
break;
}
}

}

IDispatch * pDisp;
hr = punkObject-QueryInterface(IID_IDispatch,(void**)&pDisp);
if(FAILED(hr))
{
toolStripStatusLabel1-Text = "Error querying the Interface";

}

DISPID id;
LPOLESTR Name=L"Excel";
hr = pDisp-GetIDsOfNames(IID_NULL,&Name,1,LOCALE_USER_DEFAUL T,&id);
if(FAILED(hr))
{
// I always get here. I am not sure the Name "Excel" is
correct or what to put here ? "Excel.Application" ,...?
toolStripStatusLabel1-Text = "GetIDsOfNames failed";

}

pDisp-Invoke(...)


I have found my answers : L"ActiveSheet" was a correct answer. and I
took it from here :
http://support.microsoft.com/kb/216686/EN-US/

AG.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"