Hi,
I need to close 3 workbooks from the current one.
So in the main workbook that I have open, I inserted a button, and added the following code to it:
Sub btnClose_Books()
Dim objXLBook As Workbook
For Each objXLBook In Application.Workbooks
If objXLBook.Name = "Book1" Then
objXLBook.Close (False)
ElseIf objXLBook.Name = "Book2" Then
objXLBook.Close (False)
ElseIf objXLBook.Name = "Book3" Then
objXLBook.Close (False)
End If
Next
End Sub
But after the current workbook, it doesn't even go to Next. It comes out of the Sub.
Any ideas please?
Thanks
I need to close 3 workbooks from the current one.
So in the main workbook that I have open, I inserted a button, and added the following code to it:
Sub btnClose_Books()
Dim objXLBook As Workbook
For Each objXLBook In Application.Workbooks
If objXLBook.Name = "Book1" Then
objXLBook.Close (False)
ElseIf objXLBook.Name = "Book2" Then
objXLBook.Close (False)
ElseIf objXLBook.Name = "Book3" Then
objXLBook.Close (False)
End If
Next
End Sub
But after the current workbook, it doesn't even go to Next. It comes out of the Sub.
Any ideas please?
Thanks