S sandy Mar 9, 2004 #1 Why i got error when setting alias for workbook? Dim wbk As Workbooks Set wbk = Workbooks("Book1.xls")
Why i got error when setting alias for workbook? Dim wbk As Workbooks Set wbk = Workbooks("Book1.xls")
T Tom Ogilvy Mar 9, 2004 #2 because you dimensioned wbk as workbooks with an "s". It should be Dim wbk as Workbook
S sandy Mar 9, 2004 #4 but i got an error "subscription out of range" if i use following code: Sub auto_open() Dim wbk As Workbook Set wbk = Workbooks("book2.xls") end sub
but i got an error "subscription out of range" if i use following code: Sub auto_open() Dim wbk As Workbook Set wbk = Workbooks("book2.xls") end sub
T Tom Ogilvy Mar 9, 2004 #5 That means you don't have an open workbook named Book2.xls If you just created a workbook and it is named book2 and you haven't save it, you would refer to it as set wbk = Workbooks("book2") an unsaved, new workbook does not have an .xls extension.
That means you don't have an open workbook named Book2.xls If you just created a workbook and it is named book2 and you haven't save it, you would refer to it as set wbk = Workbooks("book2") an unsaved, new workbook does not have an .xls extension.
S sandy Mar 9, 2004 #6 so is it my excel problem? because i did created the excel file named book2.xls and tried your method delete my book2.xls and create one using "book2" but still got an error
so is it my excel problem? because i did created the excel file named book2.xls and tried your method delete my book2.xls and create one using "book2" but still got an error
T Tom Ogilvy Mar 9, 2004 #7 If you have a workbook named book2.xls in the same instance of excel, then your code should work fine. I created a workbook and saved it as book2.xls. I left it open. I ran this code: Sub auto_open() Dim wbk As Workbook Set wbk = Workbooks("book2.xls") MsgBox wbk.Name End Sub with no problem. If there is no open workbook named book2.xls you will get an error that says error '9', subscript out of range.
If you have a workbook named book2.xls in the same instance of excel, then your code should work fine. I created a workbook and saved it as book2.xls. I left it open. I ran this code: Sub auto_open() Dim wbk As Workbook Set wbk = Workbooks("book2.xls") MsgBox wbk.Name End Sub with no problem. If there is no open workbook named book2.xls you will get an error that says error '9', subscript out of range.