VBA write to text file: runtime error 52 'invalid file name or number'

Public Sub EdgeColor_Click()
    Dim intInFile As Integer
    intInFile = FreeFile

    Open "c:\picturename.csv" For Output As #intFileNo
    Print #intFileNo, "test"

    Close #intFileNo
End Sub

This is my code, and I get a runtime error 52 "wrong name or file number". I tried doing as input and making the file exist, but I get the same error.

This is VBA inside the Proficy iFix graphical profile, and I cannot understand what I'm doing wrong.

+3
source share
1 answer

You mix intInFileand intFileNo.

It is possible that it intFileNojust sets to zero if you are not using a command option explicitthat might explain an invalid number.

This little command goes at the top of each of my VB / VBA files because I have been burned by this so much time.

+10

All Articles