Paul Johnson
Paul Johnson

Reputation: 323

Unable to Close Excel Workbook without SaveAs Prompt

Hi there I have thorny little problem thats causing me a major headache, I have a section of code in VB.NET where I need to close the current Excel workbook, however whenever I make the call to:

 'Now force a close of the active workbook without saving
 _myXLApp.Workbooks(1).Close(Excel.XlSaveAction.xlDoNotSaveChanges)

The SaveAs dialog gets displayed... How do I prevent this from happening? My understanding of the code is that making the call as above should close the workbook without any SaveAs prompt. Any assistance much appreciated.

Kind Regards paul J.

Upvotes: 0

Views: 1083

Answers (1)

Busse
Busse

Reputation: 863

Try this instead:

_myXLApp.Workbooks(1).Close(SaveChanges:=False) 'Instead of Excel.xlSaveAction.xlDoNotSaveChanges

This should do the trick. Any time I've closed Excel workbooks in VB.Net this is the command I use. It actually mirrors the Excel VBA Format.

Upvotes: 3

Related Questions