T
teepee
My problem is I want to use VBA to close 2 workbooks if they're open and do
nothing if they're not open.
Put it another way, if I put
Workbooks("book1.csv").Close SaveChanges:=False
Workbooks("book2.csv").Close SaveChanges:=False
and then book 1 and book 2 aren't already open, it creates a runtime error
which I don't want.
I thought this might work:
Dim wb As Workbook
If wb.Name = "book1.csv" Then
Workbooks("book1").Close SaveChanges:=False
'End If
'If wb.Name = "book2" Then
Workbooks("book2").Close SaveChanges:=False
'End If
But it doesn't. Anyone got any ideas?
nothing if they're not open.
Put it another way, if I put
Workbooks("book1.csv").Close SaveChanges:=False
Workbooks("book2.csv").Close SaveChanges:=False
and then book 1 and book 2 aren't already open, it creates a runtime error
which I don't want.
I thought this might work:
Dim wb As Workbook
If wb.Name = "book1.csv" Then
Workbooks("book1").Close SaveChanges:=False
'End If
'If wb.Name = "book2" Then
Workbooks("book2").Close SaveChanges:=False
'End If
But it doesn't. Anyone got any ideas?