exception in excel while writting to it

G

Gaurav

Hi,

i am getting an exception when trying to open an existing file and
write something into it.
if i create a new worksheet, the code works fine.
I am not able to findout the problem. Please look at the code and let
me know what is wrong with it.


ERROR_PROTECT_BEGIN_PROXY()


Range rp = m_Excel.GetRange(COleVariant("C1"),
COleVariant("C1"));
rp.SetValue2(COleVariant("Hi")); // <------throwing
Exception


ERROR_PROTECT_END_PROXY("Error Copying")


void __stdcall CExcelProxy::OnWorkBookOpen(IDispatch *Wb)
{
DEBUG_MESSAGE("Opening Workbook");


// Load Macro into VBE for callbacks
LoadMacro();


m_pWorkBook = Wb;
m_pWorkSheet = m_pWorkBook->GetActiveSheet();


m_pWorkSheet->Protect(false);


// Set class-wide indicator


IDispatchPtr pDsp;
// Get reference to comand bars
pDsp = (Office::CommandBarsPtr)m_pApp->GetCommandBars();
m_pCmdBars = pDsp.Detach();


// Release pointers
ReleaseWorkBookPtrs();
ReleaseCommandBarPtrs();



}


void __stdcall CExcelProxy::OnNewWorkBook(IDispatch *Wb)
{
IDispatchPtr pDsp;
// Get reference to comand bars
pDsp = (Office::CommandBarsPtr)m_pApp->GetCommandBars();
m_pCmdBars = pDsp.Detach();

// Show "Save" menus
UpdateSaveMenus(true);


// Release all pointers
ReleaseCommandBarPtrs();


// Load macro for callbacks
LoadMacro();
 
J

Joel

See if this works

with m_Excel
Range rp = .GetRange(.COleVariant("C1"), .COleVariant("C1"));
rp.SetValue2(.COleVariant("Hi"));
end with
 
G

Gaurav

See if this works

with m_Excel
       Range rp = .GetRange(.COleVariant("C1"), .COleVariant("C1"));
        rp.SetValue2(.COleVariant("Hi"));
end with



















- Show quoted text -

Used the same code and it is not working
 
J

Joel

I'm not an expert at using Excel with C++ and MFC. try your original code
and change from: Value2 to: Value (eliminate the 2).
 
Top