How to avert the save MessageBox prompt in Excel-VBA?

大城市里の小女人 提交于 2020-01-02 09:39:08

问题


I have a problem here if you look at my codes below after I call the .close line which was the file I initially copied from. It will prompt a save MessageBox message either yes, no, or cancel. Is there anyway I can avoid this save message from appearing programmatic if no was the case could I just programmatic program it no instead?


回答1:


Jon is right to suggest Application.DisplayAlerts and if you want to answer no to a save as you suggest

 Workbooks(Filename1).Close SaveChanges:=False



回答2:


Try setting the Application.DisplayAlerts to false, then closing. I recommend turning it back on after setting it.

Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True



回答3:


IIRC:

Workbooks(FileName1).Save

If you save it explicitly, it won't have to ask you.



来源:https://stackoverflow.com/questions/6824816/how-to-avert-the-save-messagebox-prompt-in-excel-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!