Excel 2003 Automation error

bt2003bt2003 Member Posts: 9
Hi

I am trying to create, populate and the save an excel file through the use of automation only. This is to happen without excel being visible to the user.

Navision is UK 4.00 sp3
Excel is from office 2003
Automation is Microsoft Excel 11.0 Object Library

I can create an excel worksheet successfully. The code to save it causes the error
"This message is for C/AL programmers: Could not invoke the member SaveAs. The OLE control or Automation returned the following message: The requested member does not exist, or the call tried to set the value of a read-only property."

Main bits of code for this issue are :
Global Vars:
MSExcel Automation 'Microsoft Excel 11.0 Object Library'.Application
XLBook Automation 'Microsoft Excel 11.0 Object Library'.Workbook
XLSheet Automation 'Microsoft Excel 11.0 Object Library'.Worksheet

CLEAR(MSExcel);
CREATE(MSExcel);
MSExcel.Visible(FALSE);
XLBook := MSExcel.Workbooks.Add;
XLSheet := XLBook.ActiveSheet;
XLSheet.Name := 'First Sheet';
XLBook.SaveAs('C:\test.xls');

It is the last line that generates the error. I have tried replacing the final line with XLSheet.SaveAs('C:\test.xls'), but get the same error.

Any help would be greatly appreciated.

Answers

  • SogSog Member Posts: 1,023
    Although you are creating your own automation, you should check out this handy excel tool
    This is a code extract from that tool:
    IF NOT EXISTS(WorkBookPath) THEN
      XlBook.SaveAs(WorkBookPath)
    ELSE
      XlBook.Save;
    XlBook.Close(FALSE);
    CLEAR(XlSheet);
    XlApp.Quit;
    CLEAR(XlApp);
    
    WorkbookPath is text [250] (which in your case would be 'C:\test.xls')
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • bt2003bt2003 Member Posts: 9
    Thanks for the reply sog. Have tried it, but get the same result.

    I am now beginning to suspect the my installation of office 2003.
  • SogSog Member Posts: 1,023
    You should check if you have the rights to save a file at that location (in this case the C-drive)
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • kapamaroukapamarou Member Posts: 1,152
    Can you try assigning the filename to a saveFileName text variable and doing:
        saveFileName := 'c:\123.docx';
        wDoc.SaveAs(saveFileName);
    

    I had the same problem with Word automation and it worked...
  • bt2003bt2003 Member Posts: 9
    I have carried out a repair on my office 2003, and it now works. Great!

    Thanks for the prompt replies.

    I think the problem arose because I also had just excel 2000 installed (after office 2003).
Sign In or Register to comment.