Share via

VBA run time error 53 cannot find file

Anonymous
2021-05-15T00:18:06+00:00

Hey!

I am writing this code for a class I am in to have excel open a file, read in the information in the file, and display the information in a message box. When I run the code, VBA states it cannot find my file. I know the file is correct and does exist.

Side note, the file is a plain text document but when I saved it from a word doc to .txt, it gives me an error telling me the format will change. Then VBA doesn't find it. Does anyone know how I can solve this? It doesn't happen to anyone else in the class.

Here is the code

Sub runclicked()

'Variables defined

Dim tFirstName As String

Dim tLastName As String

Dim tWrestlingName As String

Dim tCorner As String

Dim tAnnouncement As String

' open the file

Open ThisWorkbook.Path & "\wrestlingnames.txt" For Input As #1

'read the file

Input #1, tFirstName

Input #1, tLastName

Input #1, tWrestlingName

Input #1, tCorner

'close the file

Close #1

' Processing verbaige for text box

tFirstName = Trim(UCase(tFirstName))

tLastName = Trim(UCase(tLastName))

tWrestlingName = Trim(UCase(tWrestlingName))

tCorner = Trim(LCase(tCorner))

tAnnouncement = "In the " & tCorner & " corner, It's " & tFirstName & " ' " & tWrestlingName & " ' " & tLastName & " ! "

'Output

MsgBox tAnnouncement

End Sub

Any advice would be helpful at this point. Thanks!

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

5 answers

Sort by: Most helpful
  1. Anonymous
    2021-05-15T11:57:17+00:00

    Ok. Thank you. I will try it again and see if anything changes. I appreciate your help.

    Was this answer helpful?

    0 comments No comments
  2. OssieMac 48,001 Reputation points Volunteer Moderator
    2021-05-15T10:38:06+00:00

    I have tried using notepad ++ and I don't get this pop up, but it still states that it can not find my file.

    The code works for me so I think that I have to go with the reply from Andreas that the text file is not in the same folder as your Excel project or you have the incorrect spelling for the filename. Because You have indicated that you have tested with Notepad, I should think that the file type should be correct because it only saves in text type files. However, when saving from word you could test by selecting "Windows (Default)" or "MS-Dos" option on that last popup dialog.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2021-05-15T08:53:12+00:00

    Thank you for your response!

    Yes, I did save it in the save as field as plain text. When I do that, however, I get a window that pops up for file conversion and text formatting. It looks like this:

    And then I get that error in excel. I have tried using notepad ++ and I don't get this pop up, but it still states that it can not find my file.

    Was this answer helpful?

    0 comments No comments
  4. OssieMac 48,001 Reputation points Volunteer Moderator
    2021-05-15T06:00:32+00:00

    Your code works perfectly.

    Screen shot of MsgBox.

    Screen shot of Text file when opened with Notepad

    When you created the text file using "Save as   from Word, did you actually select the Plain Text (*.txt) option in the "Save as type field"? Or did you simply change the file extension in the "File name" field. The "Save as type field" must be selected.

    Was this answer helpful?

    0 comments No comments
  5. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2021-05-15T05:27:12+00:00

    When I run the code, VBA states it cannot find my file. I know the file is correct and does exist.

    ' open the file

    Open ThisWorkbook.Path & "\wrestlingnames.txt" For Input As #1

    When your Excel file is not saved and/or the file wrestlingnames.txt is not in the same folder you'll get this error.

    Andreas.

    Was this answer helpful?

    0 comments No comments