0

I have a button on a user form to let the operator close an Excel workbook that was opened previously. When the operator teys to close the file, I want it to save it first without prompting it. It builds ok in debug mode, but I get the following error on both the save and close functions at run time.

System.NullReferenceException: 'Object reference not set to an instance of an object.'

I am not sure what to do?

The following is the code.

    private void btnExcelClose_Click(object sender, EventArgs e) 
    {
        //Save the workbook
        exApp.Save(WBpath);
        
        //Close the workbook
        exApp.Workbooks.Close();

        //Renable the open button
        btExcelOpen.Enabled = true;
    }
Paula
  • 15
  • 4

0 Answers0