Krishn
Krishn

Reputation: 873

Prevent save changes dialog box upon closing

I have spreadsheet which uses events upon opening, therefore anytime I try to close the file, the save changes dialog box appears.

Is there a way to prevent this?

Upvotes: 2

Views: 2290

Answers (3)

ArBro
ArBro

Reputation: 731

You can add a function in VBA to ThisWorkbook to let Excel think that the file has been saved. This will prevent any save prompts.

If you don't want to save your workbook:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

    Me.Saved = True

End Sub

If you want to save your workbook:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

    Me.Save

End Sub

Upvotes: 3

Krishn
Krishn

Reputation: 873

Private Sub Workbook_BeforeClose(Cancel As Boolean)
 ThisWorkbook.Close SaveChanges:=False
End Sub

Upvotes: 0

R.Katnaan
R.Katnaan

Reputation: 2526

Here documentation for deleting work sheet.

So, you need to use as follow:

'Stopping Application Alerts
Application.DisplayAlerts=FALSE

'~~~~~~deleting sheet~~~~~

'Enabling Application alerts once we are done with our task
Application.DisplayAlerts=TRUE

Upvotes: 1

Related Questions