When I run the following routine, the file opens with no error:
Sub Test1()
Workbooks.Open (ThisWorkbook.Path & "\Export_CitiMD_20231221_114052.csv")
i = 1
End Sub
However, when I try to put the name of the CSV file into a cell, immediately AFTER the CSV file opens, Run-time error 91 pops up. May I know why?
Sub FindNewISINs()
Dim currentWorkbook As Workbook
Dim csvWorkbook As Workbook
Dim csvFileName As String
Set currentWorkbook = ThisWorkbook
csvFileName = currentWorkbook.Path & "\" & currentWorkbook.Sheets("Control").Range("G44").Value
Set csvWorkbook = Workbooks.Open(csvFileName) ' Error occurs at this line. CSV file did open. But Error 91 comes up and the rest of the code cannot be executed.
' <Other codes>
End Sub
Sub Test1()
Workbooks.Open (ThisWorkbook.Path & "\Export_CitiMD_20231221_114052.csv")
i = 1
End Sub
However, when I try to put the name of the CSV file into a cell, immediately AFTER the CSV file opens, Run-time error 91 pops up. May I know why?
Sub FindNewISINs()
Dim currentWorkbook As Workbook
Dim csvWorkbook As Workbook
Dim csvFileName As String
Set currentWorkbook = ThisWorkbook
csvFileName = currentWorkbook.Path & "\" & currentWorkbook.Sheets("Control").Range("G44").Value
Set csvWorkbook = Workbooks.Open(csvFileName) ' Error occurs at this line. CSV file did open. But Error 91 comes up and the rest of the code cannot be executed.
' <Other codes>
End Sub