C
Craig
Hi,
I'm trying to close one specific workbook that I've opened with the
Workbooks.Add command. This causes the workbook to come up with a name
that changes (book1, book2, etc.). After the rest of the code has
finished, I want to close this one workbook, leaving all other active
workbooks open. I've been trying to work with Workbooks.Close but that
keeps closing all workbooks. So the next thing I tried went like this.
Sub OpenandClose()
Dim wB as String
wB = "WorkBook"
Workbooks(wB).Add
'rest of code
Workbooks(wB).close
End Sub
But that's not working either - getting error 9, subscript out of range
on Workbooks(wB).Add
Any thoughts? Thanks in advance for any help.
I'm trying to close one specific workbook that I've opened with the
Workbooks.Add command. This causes the workbook to come up with a name
that changes (book1, book2, etc.). After the rest of the code has
finished, I want to close this one workbook, leaving all other active
workbooks open. I've been trying to work with Workbooks.Close but that
keeps closing all workbooks. So the next thing I tried went like this.
Sub OpenandClose()
Dim wB as String
wB = "WorkBook"
Workbooks(wB).Add
'rest of code
Workbooks(wB).close
End Sub
But that's not working either - getting error 9, subscript out of range
on Workbooks(wB).Add
Any thoughts? Thanks in advance for any help.