Hi,
I have to do the following job:
1. Open an existing Excel-File (used as template)
2. Add data to the Excel-File
3. save as new file (other filename)
4. close the new file
5. create an email an attaching the new file.
All of the above is not problem, except of #4
I do not manage to close the file an to terminate the Excel-task.
Here my code:
//
//
//
CLEAR(Excel);
IF NOT CREATE(Excel) THEN
ERROR('Excel could not be found.');
Excel.Workbooks._Open(GLSetup."Excel-File");
Book := Excel.ActiveWorkbook;
Sheet := Book.Worksheets.Item(GLSetup."Excel-Sheet");
...
Code to add data
...
Book.SaveCopyAs(GLSetup."Excel-NewFilename");
Book.Close(FALSE);
Excel.Quit;
CLEAR(Excel);
//
//
//
"Excel" = Automation.Application
"Book" = Automation.Workbook
"Sheet" = Automation.Worksheet
The result of my programming is:
The additional data is added to the Excel-File.
The File is saved with a new name.
The Workbook is closed.
The Excel-Task is still running an locking the new file.
The Excel-Task is only visible in Taskmanager, even if I make it visible before closing the workbook an quiting excel, by useing "Excel.Visible(TRUE);"
Does anyone know how to quit / close 7 terminate Excel so the new file is not locked by the Excel-task anymore?
Thankx,
Rolf
0
Comments
And if it is open, how can I close it?
Any hint is welcome.
i had the same problem, i dont know how i fixed it but now i am using the following code and dont get any error.
Good luck...
(but I created a new workbook)
BEGIN
CLEAR(Excel);
CREATE(Excel,FALSE);
Book := Excel.Workbooks.Add(-4167);
Sheet := Excel.ActiveSheet;
Sheet.Name := 'blabla';
//add data to excel sheet
Sheet._SaveAs(FileName);
Excel.Visible(TRUE);
END;
but your code "only" saves the modified sheet as a new file and than gives the user control over it.
My problem is, that the sheet must be saved under a new name and than the whole Excel-Application including any open files must be closed, so I can get control over the new file and attach it to an email.