Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove Prompt For Save on Close 2

Status
Not open for further replies.

V00D00

Technical User
Jul 11, 2005
78
US
I have a small Excel report that uses database connectivity. When the report is ran it connects to the database and does some caluclations that are populated in the excel sheet.

Apon closing the workbook I am always prompted to save changes. How would I go about removing that prompt so that there is no chance of anyone saving anything in the report?
 
To eliminate the save prompt, place the following line in the Workbook_BeforeClose event procedure:
Code:
ThisWorkbook.Saved = True

Since this is potentially dangerous when you are developing the workbook (i.e. Closing the workbook without explicitly saving will cause you to loose your work), you may want to set a constant while coding/debugging. Example, in your standard code module, create a boolean such as
Code:
Public Const DEBUGMODE As Boolean = True
Modify the BeforeClose procedure to look like:
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
   If Not DEBUGMODE Then
     ThisWorkbook.Saved = True
   End If
End Sub

Before deploying the workbook, set DEBUGMODE = False then save the workbook.


Regards,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top