View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Gaurav[_7_] Gaurav[_7_] is offline
external usenet poster
 
Posts: 2
Default exception in excel while writting to it

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();