Chris Davison
MrExcel MVP
- Joined
- Feb 15, 2002
- Messages
- 1,790
I'm trying to close a workbook in VBA but it's not even starting the subroutine......
the workbook name is in cell A1, which changes, so I can't hard-code it's name :
<code>
Sub import_files()
sourceworkbook = range("A1").Value
'open source
Workbooks.Open Filename:=sourceworkbook
..... lots of copy paste stuff......
'close source workbook
Workbooks(sourceworkbook).close
End Sub
</code>
I get runtime error 9 : subscript out of range on the "Workbooks(sourceworkbook).close" line
if I omit the "Workbooks(sourceworkbook).close" everything works fine, but I'm left with that workbook sitting open, which needs to be closed
I know I'm missing something simple....
thanks
Chris
the workbook name is in cell A1, which changes, so I can't hard-code it's name :
<code>
Sub import_files()
sourceworkbook = range("A1").Value
'open source
Workbooks.Open Filename:=sourceworkbook
..... lots of copy paste stuff......
'close source workbook
Workbooks(sourceworkbook).close
End Sub
</code>
I get runtime error 9 : subscript out of range on the "Workbooks(sourceworkbook).close" line
if I omit the "Workbooks(sourceworkbook).close" everything works fine, but I'm left with that workbook sitting open, which needs to be closed
I know I'm missing something simple....
thanks
Chris