January 3rd, 2003, 7:56 am
void main(){ using namespace Excel; _ApplicationPtr pXL; try { pXL.CreateInstance(L"Excel.Application.9"); pXL->Visible = VARIANT_TRUE; WorkbooksPtr pBooks = pXL->Workbooks; _WorkbookPtr pBook = pBooks->Open("c:\\wilmex\\DomSheet.xls"); double q=42; pXL->Range["Sheet2!A1"]->Value2=q; pXL->Save(); } catch(_com_error &e) { dump_com_error(e); }}This shouldn't be too hard to follow, once you've navigated to the interface, you've got the object model for Excel that you will recognise from VBA.The less intuitive bit is conning VC++ to pick up the library.At the top of the file, you need to put someting like#import <mso9.dll> no_namespace rename("DocumentProperties", "DocumentPropertiesXL") #import "C:\Program Files\Common Files\Microsoft Shared\VBA\vbeext1.olb" no_namespace #import <excel9.olb> rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interfacesThe paths given here may not work on your machine, in particular mso9.dll may not be on your machine at all. Scan for MSO*.dll, and pick the one with the highest number.The final #import is a fudge I picked up somewhere, to get around the way Excel functions clash with Win32 ones.Contact me directly if you want the project.