tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,834
- Office Version
- 365
- 2019
- Platform
- Windows
I am trying to refer to a workbook saved on my PC but I don't know why the following code doesn't work:
The error message is:
When I recorded a macro to open the workbook, this code was generated:
so I know my file and its location is correct.
Code:
Dim wb As Workbook
Set wb = Workbooks("C:\Users\myname\Documents\myexcelfile.xlsm")
The error message is:
Code:
Run-time error '9'
Subscript out of range
When I recorded a macro to open the workbook, this code was generated:
Code:
Workbooks.Open Filename:="C:\Users\myname\Documents\myexcelfile.xlsm"
so I know my file and its location is correct.