locked
Dialog box while closing workbook programmatically RRS feed

  • Question

  • I needed to copy sheets from another workbook, to the Excel Document Level AddIn which I am working in. I have used the following code to open the Excel file selected :-

    Dim workbook As Excel.Workbook = Globals.ThisWorkbook.Application.Workbooks.Open(OpenWorkSheetDialog.FileName)
    workbook.IsAddin = True
    (IsAddin is set to true so that the new Workbook opened does not open up a new Excel Window)

    However, during the workbook.close() method call, I am always getting the "Do you want to save the changes to ..." Excel dialog box.

    workbook.Close(SaveChanges:=False)

    Please let me know, how I can prevent the appearing of this dialog box and close the file. I have tried setting DisplayAlert = False and ScreenUpdating = False.



    Friday, October 23, 2009 7:36 PM

Answers

  • Hi Aritra Saha!

    You could try setting the Saved property of the Workbook.
    The workbook is not saved but it tells Excel that it is.
    Thus, the dialog is not shown.


    Excel.Workbook workbook;

    workbook.Saved = true;

    Saturday, October 24, 2009 8:17 AM

All replies

  • Hi Aritra Saha!

    You could try setting the Saved property of the Workbook.
    The workbook is not saved but it tells Excel that it is.
    Thus, the dialog is not shown.


    Excel.Workbook workbook;

    workbook.Saved = true;

    Saturday, October 24, 2009 8:17 AM
  • Thanks Jose for the reply.

    This works now.
    Monday, October 26, 2009 1:00 PM