Run-time error= '5': invalid procedure call or argument

taka305

New Member
Joined
Feb 4, 2014
Messages
1
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
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,214,787
Messages
6,121,569
Members
449,038
Latest member
Guest1337

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