- wxMessageBox("Please ensure Excel is running, then press OK.\nThe active cell should then say 'wxWindows automation test!' in bold.");
-
- wxAutomationObject excelObject, rangeObject;
- if (!excelObject.GetInstance("Excel.Application"))
- {
- if (!excelObject.CreateInstance("Excel.Application"))
+ wxMessageBox(wxT("Excel will be started if it is not running after you have pressed OK button.")
+ wxT("\nThe active cell should then say 'wxWidgets automation test!' in bold."),
+ wxT("Excel start"));
+
+ wxAutomationObject excelObject;
+ if ( !excelObject.GetInstance(wxT("Excel.Application")) )
+ {
+ wxLogError(wxT("Could not create Excel object."));
+ return;
+ }
+
+ // Ensure that Excel is visible
+ if (!excelObject.PutProperty(wxT("Visible"), true))
+ {
+ wxLogError(wxT("Could not make Excel object visible"));
+ }
+ const wxVariant workbooksCountVariant = excelObject.GetProperty(wxT("Workbooks.Count"));
+ if (workbooksCountVariant.IsNull())
+ {
+ wxLogError(wxT("Could not get workbooks count"));
+ return;
+ }
+ const long workbooksCount = workbooksCountVariant;
+ if (workbooksCount == 0)
+ {
+ const wxVariant workbook = excelObject.CallMethod(wxT("Workbooks.Add"));
+ if (workbook.IsNull())