Hello. I need some help. Hopefully it's something simple.
I am trying to open a txt file, but I get an error message that says
"Run-time error '52':
Bad file name or number
The file name is correct. I tried two ways to pass the name -- as a variable and from Application.GetOpenFilename("Text Files (*.txt), *.txt")
The line where VBA complains is "Open fileToOpen For Input As #InFile"
Function ReadFile()
Dim InFile As Integer, fileToOpen As String, strLine As String
fileToOpen = Application.GetOpenFilename("Text Files (*.txt), *.txt")
Open fileToOpen For Input As #InFile '<-- Error happens here
Do While Not EOF(InFile)
Line Input #InFile, strLine
Debug.Print strLine
Loop
Close #InFile
End Function
Any help is much appreciated.
Thank you,
Angel
Bookmarks