I am importing a .txt file and reformatted the data to remove commas. When I try to save it, it give me the run time error. How can I fix this? Any help would greatly be appreciated!
Sub SaveNewFile()
ActiveCell.SpecialCells(xlLastCell).Select
endrow = Selection.Row
Cells(1, 1).Select
If TopSide = 1 Then
    BoardName = BoardName & "_TOP"
Else
    BoardName = BoardName & "_BOT"
End If
filesavename = Application.GetSaveAsFilename( _
    InitialFilename:=BoardName, FileFilter:="YTV CAD Files (*.ycd), *.ycd")
    If filesavename = "False" Then End
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile(filesavename, True)
    For i = 1 To 17
        For j = 1 To 2
            a.write (Cells(i, j) & "     ")
        Next j
        a.writeline
    Next i
    For i = 18 To endrow
        For j = 1 To 7
            a.write (Cells(i, j) & "     ")
        Next j
        a.writeline
    Next i
    a.Close
    Application.DisplayAlerts = False
    'ActiveWorkbook.SaveAs Filename:= _
    '    filesavename, _
    '    FileFormat:=xlTextPrinter, CreateBackup:=False
    jmessage = MsgBox(filesavename & " has been generated successfully!", vbOKOnly, "YCD Export")
    Call YCDFileLocationIni
    'Application.DisplayAlerts = True
    Workbooks.Open (CADFileName)
    Workbooks(ShortCADFileName).Activate
    ActiveWorkbook.Close
End Sub
 
     
    