So I'm basically transferring code from one workbook to the other. I'm opening a file through file pickers in both cases the code is identical:
Private Sub ImportData_Click()
(... irrelevant stuff...)
With fileDialog
'The file stores the last path chosen by the user. Goes there first.
'Otherwise, defaults to the workbook's location because we know it exists
If file_exists(Range(ThisWorkbook.Names("cst_last_import_folder")).Value) Then
(... more irrelevent stuff...)
End Sub
The Range() method fails in the new workbook (runtime 1004 error), but not in the old one. It took me a while to figure out - but that's because in the old book, this part is actually done within a module. In the new workbook, this bit of code is hosted directly on the sheet.
So I know how it fails - e.g. the Range() methode doesn't work if the code resides on the worksheet. But why is it so? E.g. what causes the method to fail only if hosted on the worksheet? Or is there a more fundamental reason behind this that I am missing?