ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   To say "no" with vba (https://www.excelbanter.com/excel-programming/273034-say-no-vba.html)

Peter[_18_]

To say "no" with vba
 
Hi,
I have a macro
....Windows("Data.xls").Activate
ActiveWindow.Close
Application.ScreenUpdating = True

.....

that closes the workbook and it ask me everytime "Do you
want to save the changes you made?" and i must click it NO
Is it possibile not having this question automatize the
answer "NO". Regards
Pet

Harald Staff[_5_]

To say "no" with vba
 
Hi Pet

You should close the workbook, not the window, or it will err if it has more than one windows. What you want is
"Application.DisplayAlerts". Also, setting Saved to true would avoid the message. Try this, it uses both techniques and should be
100% foolproof:

Sub CloseIt()
On Error Resume Next
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Workbooks("Data.xls").Saved = True
Workbooks("Data.xls").Close
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

--
HTH. Best wishes Harald
Excel MVP

Followup to newsgroup only please.

"Peter" skrev i melding ...
Hi,
I have a macro
...Windows("Data.xls").Activate
ActiveWindow.Close
Application.ScreenUpdating = True

....

that closes the workbook and it ask me everytime "Do you
want to save the changes you made?" and i must click it NO
Is it possibile not having this question automatize the
answer "NO". Regards
Pet





All times are GMT +1. The time now is 01:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com