1
votes

I'am looking for the VBA-code for closing all open workbooks without saving and then open an another workbook.

Nows anybody the correct VBA-code?

I have now the follow code:

Private Sub Workbook_Open()
Dim WB As Workbook

For Each WB In Workbooks
    If Not (WB Is ActiveWorkbook) Then WB.Close
Next

End Sub

This one i haven't tried jet. I try to make a macro dat starts every day one the same time and closed all workbooks. Then opens workbooks and update the data.

2
just slight amendment to your code for it to NOT save changes: WB.Close savechanges:=FalseRaugmor

2 Answers

2
votes

I have adjust WB.Close savechanges:=False to the VBA-code and its works perfect.

Thanks

0
votes

In my opinion, using macro is not a good way to do this. Check this out. http://blog.contextures.com/archives/2013/04/25/close-all-files-in-excel-2013/

Or you could do this using cmd command like

taskkill /IM excel.exe /F
start excel.exe

or making a batch file or a vbscript doing the same.