0

I am attempting open a csv file with this code and it keeps giving me an "error 52 bad file name or number"

 Sub ShowFileDialog()
   Dim x As String
     Dim FF1 As Integer
    Dim dlgOpen As FileDialog
    Set dlgOpen = Application.FileDialog( _
        msoFileDialogFilePicker)
    With dlgOpen

        .Show
    End With

x = CStr(dlgOpen.SelectedItems(1))
MsgBox x

Open x For Input As #FF1

Do While Not EOF(FF1)

Line Input #FF1, inputdata

Dim lineData() As String
lineData() = Split(inputdata, ",")



Loop
Close #FF1
End Sub

The debugger is highlighting the Open for X line but I am feeding it the path name as a string

1
  • 1
    You never set FF1 to a file no. FF1 = FreeFile before opening. Commented Oct 12, 2012 at 14:45

1 Answer 1

1

Add this line directly before the line causing the error:

FF1 = FreeFile

Because Open For Input Requires a number between 1 and 512, which should be obtained via a call to FreeFile.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.