Reputation: 125
Sub test()
Name = "C:\Users\zif\Desktop\CAT\as1_new\tt.xlsx"
wb = Application.Workbooks.Open("C:\Users\zif\Desktop\CAT\as1_new\tt.xlsx")
End Sub
this is my code and i just want to test it. I am sure the directory and filename is correct, and the file is not opened, but i still have this error
update: Thank you for answering my questions I have changed my code to below:
Sub test()
Dim wb As Workbook
myName = "C:\Users\zif\Desktop\CAT\as1_new\tt.xlsx"
Set wb=Application.Workbooks.Open("C:\Users\zif\Desktop\CAT\as1_new\tt.xlsx")
End Sub
but it still throws the same error message to me.
Upvotes: 2
Views: 654
Reputation: 2199
I think you'll have to initialize wb
first, like this:
Dim wb As Workbook
When assigning th object you need to use the Set
statement, like this:
Set wb = Application.Workbooks.Open("C:\Users\zif\Desktop\CAT\as1_new\tt.xlsx")
Edit: There is a lot of good additional advice in the comments to the question, which should be considered.
Upvotes: 2