SaveAs method of Workbook class faile

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
buda56
Junior Coder
Posts: 20
Joined: Thu Aug 07, 2008 10:45 am

SaveAs method of Workbook class faile

Post by buda56 » Sun Dec 07, 2008 11:52 am

Hi,
I am getting the above error when trying to open a csv file in Excel and then saving the file as an Excel file (line 14 column 4).
Can anyone please advise a fix to resolve this, I have included my macro below..


VBSTART
Dim xlApp
Dim xlBook

'Opens the Excel file in Excel
Sub OpenCSVFile(filename)
Set xlApp = CreateObject("Excel.Application")
xlApp.visible = True
Set xlBook = xlApp.Workbooks.open(filename)
end sub

'Save file in Excel format
Sub SaveAsExcel(FileName)
xlBook.SaveAs(FileName), xlExcel8
End Sub

'Use this to close Excel later
Sub CloseExcel
xlApp.quit
Set xlApp = Nothing
End Sub

VBEND

//Open File then re-save as Excel file

VBRun>OpenCSVFile,C:\Users\Pztydr\Documents\MyWebSites\TeamMgr\WorkMgt\WrkImport\Tasks\Rpt-TClosed.csv
VBRun>SaveAsExcel,c:\C:\Users\Pztydr\Documents\MyWebSites\TeamMgr\WorkMgt\WrkImport\Tasks\Rpt-TClosed.xls
VBRun>CloseExcel



Regards..
Peter

buda56
Junior Coder
Posts: 20
Joined: Thu Aug 07, 2008 10:45 am

Post by buda56 » Sun Dec 07, 2008 11:58 am

Hi,
Noticed a double c: in the save filename and removed it, still getting the error though..

Regards..
Peter

buda56
Junior Coder
Posts: 20
Joined: Thu Aug 07, 2008 10:45 am

Post by buda56 » Sun Dec 07, 2008 12:20 pm

Hi,
Have resolved my problem, the issue was the definition of the file format to save in.

I had to use "-4143"

Regards..
Peter.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts