- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
After your first line of code for MessageBox.Show, where you ask the user if they want to close Excel, you then immediately Quit Excel, before checking the answer to that question. Then immediately after you quit the Excel application, you are trying to obtain a reference to Excel again, using GetObject, then trying to find that same Workbook again, which seems like an inefficient process. If you are planning on writing stuff to that Excel file after you create it, then use SaveAs on it, then you will want to leave the Excel application open, and maintain those original variables throughout the rest of your code, then use those same variables to save and close the Workbook, and quit the Excel application at the end, instead of finding the Excel application and the Workbook again at the end. Even though you used SaveAs on the new Workbook, the excekWorkbook variable should still be representing that Workbook. If you used Workbook.SaveCopyAs, then the the excelWorkbook variable would no longer be representing that other new file, but would still be representing the original file.
Wesley Crihfield
(Not an Autodesk Employee)