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