Error 53 at 'Open filename for Output'

Tony007

New Member
Joined
Jun 2, 2009
Messages
14
I try to make a macro for saving an Excel sheet to a .CSV file with "@" as delimiter.
At the line "Open fname For Output As #fnum", the Error 53, "no file found" occurs.
The Excel-help is saying that if the file is not present, a new file will be made.
This error occurs now and then, How to proceed?
Full macro:
Code:
Sub SaveAsCSV()
Path = "O:\actueel\"
Fname1 = Path & Range("E2").Value & ".csv"
fname = Application.GetSaveAsFilename(Fname1, "CSV bestand (*.csv), *.csv", , "")
If fname = False Then
MsgBox "Macro Geannuleerd"
Exit Sub
End If
sep = "@"
fnum = FreeFile
Close #fnum
Open fname For Output As #fnum
lastrow = Range("K65536").End(xlUp).Row
For Row = 2 To lastrow
A = Cells(Row, 4).Value
B = Cells(Row, 1).Value
Print #fnum, A & sep & B & sep 
Next Row
Close #fnum
End Sub
 
Last edited by a moderator:
Problem solved.
The Error53 still occurs in the Open For Output line, so now i use the following code, NOT using Open For Output anymore!

Code:
Sub SaveAsCsv2()
Application.ScreenUpdating = False
Pad = "O:\actueel\"
Fname1 = Pad & Range("E2").Value & ".csv"
fname = Application.GetSaveAsFilename(Fname1, "CSV bestand (*.csv), *.csv", , "")

If fname = False Then
    MsgBox "Macro Ended"
    Exit Sub
End If
sep = "@"
'change colnrs from original layout
kolnr = Array(4, 1, 3, 3, 5, 4, 11, 15, 10, 16)

eindrij = Range("B65000").End(xlUp).Row
eindkol = Range("HA1").End(xlToLeft).Column
tempkol = eindkol + 2
eindarray = 8

For rij = 2 To eindrij
        TempString = ""
        For kol = 0 To eindarray
            If kol <> eindarray Then
                TempString = TempString & Cells(rij, kolnr(kol)).Value & sep
            Else
                TempString = TempString & Cells(rij, kolnr(kol)).Value
            End If
        Next
        Cells(rij, tempkol).Value = TempString
Next
Range(Cells(2, tempkol), Cells(eindrij, tempkol)).Copy
Worksheets.Add
ActiveSheet.Name = "temp"
Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
Application.CutCopyMode = False

'save file as text file
ActiveWorkbook.SaveAs Filename:=fname, FileFormat:=xlTextMSDOS

'delete extra column and sheet "temp"
Sheets("Exported Pro.File Data").Activate
Columns(tempkol).Delete
Application.DisplayAlerts = False
Sheets("temp").Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "Bestand " & fname & " is aangemaakt."
End Sub
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,215,477
Messages
6,125,036
Members
449,205
Latest member
Eggy66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top