I am wondering if it is possible to make a macro in an excel file that upon the user printing the file, it closes excel and if the user is prompted to save the macro automatically pushes no.
You could either cause Excel to Quit or the workbook to close. Either way, the code needs to go in a Workbook_BeforePrint sub in the ThisWorkbook code pane.
Code:
Private Sub Private Sub Workbook_BeforePrint(Cancel As Boolean)
Application.DisplayAlerts = False
'ThisWorkbook.Close savechanges:=False 'I get an error with this statement in Excel 97
Application.Quit 'This statement works fine
End Sub
As noted in the code comments, I got a fatal error when trying to close the workbook programmatically (the workbook closed, but Excel then crashed).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.