I've been writing this vbs in excel to sort through some txt data and reformat it into excel. However, when I read in the .txt file, when it tries to save, it gives me this error:
Run-time error = '5': invalid procedure call or argument
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
Run-time error = '5': invalid procedure call or argument
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