Results 1 to 2 of 2

Thread: run time error 52

  1. #1

    Thread Starter
    Registered User
    Join Date
    Feb 2013

    run time error 52

    I was running an application for checking parameters in excel file when the messege showed " run time error 52". Please help how to solve this. below is the area where i encountered this problem.

    Private Sub CommandFormat_Click()
    Dim FileSize As Long


    If CheckBox1 = True Then
    FileNumber4 = 2
    Open "C:\IOlistErrors.txt" For Append As FileNumber4 "--------------------------- the problem was highlighted in this command line"
    Print #FileNumber4, ""
    Print #FileNumber4, "<< FILE CHECKED: '" & Workbooks(DAiowb).name & "' >> " & DateTime.Date & " " & DateTime.Time
    Print #FileNumber4, ""
    Print #FileNumber4, ""
    Print #FileNumber4, ""
    Close #FileNumber4

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    New Amsterdam

    Re: run time error 52

    Error 52 means "bad file name or number"...

    If you can ensure that exists then the only problem the file number: in your case you assigned the 2 which is (most likely) already being used.
    To avoid this type of error use FreeFile() function that returns next available number:
    Option Explicit
    Private Sub Command1_Click()
    Dim fileNum As Integer
        fileNum = FreeFile()
        Open "..." For Append As #fileNum
            'rest of your code goes here
        Close #fileNum
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width