I'm trying to add some text to a cell in Excel. It fails! Can anyone tell me why? I can easily change the name of the sheet, but not add anything to the sheet's cells. Visual Studio 6 & Excel XP


#include "stdafx.h
#pragma warning(disable: 4146
#pragma warning(disable: 4244

#import "C:\Program Files\Common Files\Microsoft Shared\Office10\MSO.DLL
#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBa6\VBE6EXT.OLB
#import "C:\Program Files\Microsoft Office\Office10\Excel.exe" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interface

const CLSID CLSID_Excel = {0x00024500,0x0000,0x0000,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}}

int APIENTRY WinMain(HINSTANCE hInstance
HINSTANCE hPrevInstance
LPSTR lpCmdLine
int nCmdShow


Excel::_ApplicationPtr xl
Excel::_WorkbookPtr xb
Excel::_WorksheetPtr xs
Excel::IRangePtr xr

CoInitialize(0)

if (FAILED(xl.CreateInstance(CLSID_Excel))

MessageBox(GetFocus(), "CreateInstance Failed", "Excel", MB_OK)

xb=xl->Workbooks->Add()

xs=xb->ActiveSheet

xs->PutName(_bstr_t("My Sheet")); //This work
xl->Visible=true

xr=xs->Range["B4"]; //This fail

xr->Value="Here is some text";//this is never writte

CoUnInitialize()

return 0

Re: Automating Excel XP by songie

songie
Wed May 12 14:26:54 CDT 2004

try
xr=xs->Range("B4");

??


"Siwix" <anonymous@discussions.microsoft.com> wrote in message
news:F996AE7C-C2F1-430F-AFB1-857B74985E37@microsoft.com...
> I'm trying to add some text to a cell in Excel. It fails! Can anyone tell
me why? I can easily change the name of the sheet, but not add anything to
the sheet's cells. Visual Studio 6 & Excel XP.
>
>
>
> #include "stdafx.h"
> #pragma warning(disable: 4146)
> #pragma warning(disable: 4244)
>
> #import "C:\Program Files\Common Files\Microsoft Shared\Office10\MSO.DLL"
> #import "C:\Program Files\Common Files\Microsoft
Shared\VBA\VBa6\VBE6EXT.OLB"
> #import "C:\Program Files\Microsoft Office\Office10\Excel.exe"
rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL")
rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interfaces
>
> const CLSID CLSID_Excel =
{0x00024500,0x0000,0x0000,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
>
> int APIENTRY WinMain(HINSTANCE hInstance,
> HINSTANCE hPrevInstance,
> LPSTR lpCmdLine,
> int nCmdShow)
> {
>
> Excel::_ApplicationPtr xl;
> Excel::_WorkbookPtr xb;
> Excel::_WorksheetPtr xs;
> Excel::IRangePtr xr;
>
> CoInitialize(0);
>
> if (FAILED(xl.CreateInstance(CLSID_Excel)))
> {
> MessageBox(GetFocus(), "CreateInstance Failed", "Excel", MB_OK);
> }
> xb=xl->Workbooks->Add();
>
> xs=xb->ActiveSheet;
>
> xs->PutName(_bstr_t("My Sheet")); //This works
> xl->Visible=true;
>
> xr=xs->Range["B4"]; //This fails
>
> xr->Value="Here is some text";//this is never written
>
> CoUnInitialize();
>
> return 0;
> }
>



Re: Automating Excel XP by Siwix

Siwix
Wed May 12 15:04:46 CDT 2004

Thanks, but Range is an array, not a function.

"songie D" <songie@D.com> wrote in message
news:esYVUcFOEHA.3832@TK2MSFTNGP10.phx.gbl...
> try
> xr=xs->Range("B4");
>
> ??
>
>
> "Siwix" <anonymous@discussions.microsoft.com> wrote in message
> news:F996AE7C-C2F1-430F-AFB1-857B74985E37@microsoft.com...
> > I'm trying to add some text to a cell in Excel. It fails! Can anyone
tell
> me why? I can easily change the name of the sheet, but not add anything to
> the sheet's cells. Visual Studio 6 & Excel XP.
> >
> >
> >
> > #include "stdafx.h"
> > #pragma warning(disable: 4146)
> > #pragma warning(disable: 4244)
> >
> > #import "C:\Program Files\Common Files\Microsoft
Shared\Office10\MSO.DLL"
> > #import "C:\Program Files\Common Files\Microsoft
> Shared\VBA\VBa6\VBE6EXT.OLB"
> > #import "C:\Program Files\Microsoft Office\Office10\Excel.exe"
> rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL")
> rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interfaces
> >
> > const CLSID CLSID_Excel =
> {0x00024500,0x0000,0x0000,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
> >
> > int APIENTRY WinMain(HINSTANCE hInstance,
> > HINSTANCE hPrevInstance,
> > LPSTR lpCmdLine,
> > int nCmdShow)
> > {
> >
> > Excel::_ApplicationPtr xl;
> > Excel::_WorkbookPtr xb;
> > Excel::_WorksheetPtr xs;
> > Excel::IRangePtr xr;
> >
> > CoInitialize(0);
> >
> > if (FAILED(xl.CreateInstance(CLSID_Excel)))
> > {
> > MessageBox(GetFocus(), "CreateInstance Failed", "Excel", MB_OK);
> > }
> > xb=xl->Workbooks->Add();
> >
> > xs=xb->ActiveSheet;
> >
> > xs->PutName(_bstr_t("My Sheet")); //This works
> > xl->Visible=true;
> >
> > xr=xs->Range["B4"]; //This fails
> >
> > xr->Value="Here is some text";//this is never written
> >
> > CoUnInitialize();
> >
> > return 0;
> > }
> >
>
>



Re: Automating Excel XP by Simon

Simon
Wed May 12 19:17:42 CDT 2004

"Siwix" <news@wixoe.no> wrote in message
news:ONqNX0FOEHA.3420@TK2MSFTNGP11.phx.gbl...
> Thanks, but Range is an array, not a function.

Indeed. I think songie D was writing in VBx notation where Range(blah) would
be a subscript to the array and not a function call.

I'm doing this OTTOMH but I remember it's a tricky bugger in Excel to get a
single cell that you can write to-- as Range.Cells also (IIRC) returns a
Range. But I think somehow if you have a Range that happens to be a Cell
then you can QI for Cell and do your work if it succeeds.

I'm sorry this isn't more helpful but perhaps would give you something to
search on....





Re: Automating Excel XP by songie

songie
Sat May 15 08:16:17 CDT 2004

Range() tends to be thought of as an array, but that's only because most
programmers of Excel probably only use VBA. As far as COM goes,
it's a property, but one that that takes parameters.
How this would translate to a function call in C++ I don't know exactly.

"Simon Trew" <ten.enagro@werts> wrote in message
news:ORpT0%23HOEHA.3264@tk2msftngp13.phx.gbl...
> "Siwix" <news@wixoe.no> wrote in message
> news:ONqNX0FOEHA.3420@TK2MSFTNGP11.phx.gbl...
> > Thanks, but Range is an array, not a function.
>
> Indeed. I think songie D was writing in VBx notation where Range(blah)
would
> be a subscript to the array and not a function call.
>
> I'm doing this OTTOMH but I remember it's a tricky bugger in Excel to get
a
> single cell that you can write to-- as Range.Cells also (IIRC) returns a
> Range. But I think somehow if you have a Range that happens to be a Cell
> then you can QI for Cell and do your work if it succeeds.
>
> I'm sorry this isn't more helpful but perhaps would give you something to
> search on....
>
>
>
>



Re: Automating Excel XP by Siwix

Siwix
Sat May 15 17:56:27 CDT 2004

I'm not sure, but I've seen the range["B2"] in different examples, event
from Microsoft.

Could it simply be that my import lines are wrong?




"songie D" <songie@d.com> wrote in message
news:%23wJzu9nOEHA.3124@TK2MSFTNGP12.phx.gbl...
> Range() tends to be thought of as an array, but that's only because most
> programmers of Excel probably only use VBA. As far as COM goes,
> it's a property, but one that that takes parameters.
> How this would translate to a function call in C++ I don't know exactly.
>
> "Simon Trew" <ten.enagro@werts> wrote in message
> news:ORpT0%23HOEHA.3264@tk2msftngp13.phx.gbl...
> > "Siwix" <news@wixoe.no> wrote in message
> > news:ONqNX0FOEHA.3420@TK2MSFTNGP11.phx.gbl...
> > > Thanks, but Range is an array, not a function.
> >
> > Indeed. I think songie D was writing in VBx notation where Range(blah)
> would
> > be a subscript to the array and not a function call.
> >
> > I'm doing this OTTOMH but I remember it's a tricky bugger in Excel to
get
> a
> > single cell that you can write to-- as Range.Cells also (IIRC) returns a
> > Range. But I think somehow if you have a Range that happens to be a Cell
> > then you can QI for Cell and do your work if it succeeds.
> >
> > I'm sorry this isn't more helpful but perhaps would give you something
to
> > search on....
> >
> >
> >
> >
>
>



Re: Automating Excel XP by songie

songie
Sun May 16 07:49:51 CDT 2004

I think that might be in C#.

"Siwix" <news@wixoe.no> wrote in message
news:%237KyeCtOEHA.3884@TK2MSFTNGP12.phx.gbl...
> I'm not sure, but I've seen the range["B2"] in different examples, event
> from Microsoft.
>
> Could it simply be that my import lines are wrong?
>
>
>
>
> "songie D" <songie@d.com> wrote in message
> news:%23wJzu9nOEHA.3124@TK2MSFTNGP12.phx.gbl...
> > Range() tends to be thought of as an array, but that's only because most
> > programmers of Excel probably only use VBA. As far as COM goes,
> > it's a property, but one that that takes parameters.
> > How this would translate to a function call in C++ I don't know exactly.
> >
> > "Simon Trew" <ten.enagro@werts> wrote in message
> > news:ORpT0%23HOEHA.3264@tk2msftngp13.phx.gbl...
> > > "Siwix" <news@wixoe.no> wrote in message
> > > news:ONqNX0FOEHA.3420@TK2MSFTNGP11.phx.gbl...
> > > > Thanks, but Range is an array, not a function.
> > >
> > > Indeed. I think songie D was writing in VBx notation where Range(blah)
> > would
> > > be a subscript to the array and not a function call.
> > >
> > > I'm doing this OTTOMH but I remember it's a tricky bugger in Excel to
> get
> > a
> > > single cell that you can write to-- as Range.Cells also (IIRC) returns
a
> > > Range. But I think somehow if you have a Range that happens to be a
Cell
> > > then you can QI for Cell and do your work if it succeeds.
> > >
> > > I'm sorry this isn't more helpful but perhaps would give you something
> to
> > > search on....
> > >
> > >
> > >
> > >
> >
> >
>
>



Re: Automating Excel XP by Igor

Igor
Wed May 19 14:17:17 CDT 2004

"Siwix" <news@wixoe.no> wrote in message
news:%237KyeCtOEHA.3884@TK2MSFTNGP12.phx.gbl
> I'm not sure, but I've seen the range["B2"] in different examples,
> event from Microsoft.

This syntax calls a method with a DISPID of DISPID_EVALUATE.
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken