To say "no" with vba

P

Peter

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
 
H

Harald Staff

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top