shetlandbob
Programmer
Hello,
I have a dialog window which has a Microsoft Office Spreadsheet10 activeX object inserted into it. I assigned a variable to this object which it defines automatically as CSpreadsheet1 SS (and i have called this SS).
On my dialog I also have a button which when pressed I want the name of the active sheet to alter and the value in cells"A1" to change.
I have included the code below, showing the class definition and the code used when the button is pressed. It compiles ok with no warnings, however the problem is that when I press the button I get a access violation error (Unhandled exception at 0x7c59ba9d in excelTest.exe: Microsoft C++ exception: _com_error @ 0x0012efc4.) to be presice. adn I have the break/continue/help options (which I have tried all but have not got anywhere)
Anyone know what I'm doing wrong? Any help much appreciated. Thanks in advance.
I have a dialog window which has a Microsoft Office Spreadsheet10 activeX object inserted into it. I assigned a variable to this object which it defines automatically as CSpreadsheet1 SS (and i have called this SS).
On my dialog I also have a button which when pressed I want the name of the active sheet to alter and the value in cells"A1" to change.
I have included the code below, showing the class definition and the code used when the button is pressed. It compiles ok with no warnings, however the problem is that when I press the button I get a access violation error (Unhandled exception at 0x7c59ba9d in excelTest.exe: Microsoft C++ exception: _com_error @ 0x0012efc4.) to be presice. adn I have the break/continue/help options (which I have tried all but have not got anywhere)
Anyone know what I'm doing wrong? Any help much appreciated. Thanks in advance.
Code:
class CexcelTestDlg : public CDialog
{
// Construction
public:
// Standard constructor
CexcelTestDlg(CWnd* pParent = NULL);
// Dialog data
enum { IDD = IDD_EXCELTEST_DIALOG };
protected:
// DDX/DDV support
virtual void DoDataExchange(CDataExchange* pDX);
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
CSpreadsheet1 SS;
afx_msg void OnBnClickedOk();
};
Code:
#include "stdafx.h"
#import "progid:Excel.Sheet" auto_search auto_rename rename_search_namespace("Office10")
void CexcelTestDlg::OnBnClickedOk()
{
using namespace Excel;
CSpreadsheet1* Ss;
Ss = &SS;
_WorksheetPtr sheet;
sheet = Ss->get_ActiveSheet();
sheet->Range["A1"]->Value2 = "10";
sheet->Name = "MY NEW SHEET NAME";
}