Forum Discussion
AnthonyDavisSF
Sep 20, 2023Copper Contributor
Workbook reference returns subscript out of range error
Bit embarrassing, but here I am... Currently struggling up the cliff that is self-learning VBA via yt and google while simultaneously trying to create a usable macro and I feel like I'm missing s...
- Sep 20, 2023
Replace the two lines
Workbooks.Open ("C:\Users\Anthony\SynologyDrive\Foldername\Sample Tracker.xlsx")
Set Trackingwbk = Workbooks("C:\Users\Anthony\SynologyDrive\Foldername\Sample Tracker.xlsx")
with
Set Trackingwbk = Workbooks.Open ("C:\Users\Anthony\SynologyDrive\Foldername\Sample Tracker.xlsx")
AnthonyDavisSF
Sep 20, 2023Copper Contributor
Thank you! The reference issue makes sense now, I think.
So, let's see if I understand. If I kept OPEN as a separate line, then SET would only use the file name instead of the full path?
Workbooks.Open ("C:\Users\Anthony\SynologyDrive\Foldername\Sample Tracker.xlsx")
Set Trackingwbk = Workbooks("Sample Tracker.xlsx")
Would that work? Not that I'll use it, just trying to understand more.
So, let's see if I understand. If I kept OPEN as a separate line, then SET would only use the file name instead of the full path?
Workbooks.Open ("C:\Users\Anthony\SynologyDrive\Foldername\Sample Tracker.xlsx")
Set Trackingwbk = Workbooks("Sample Tracker.xlsx")
Would that work? Not that I'll use it, just trying to understand more.
HansVogelaar
Sep 20, 2023MVP
Yes, that should work too.
- AnthonyDavisSFSep 20, 2023Copper Contributor
I understand now, thank you again! You've been a huge help.