Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel save as csv

Status
Not open for further replies.

JoeNg

Programmer
Apr 17, 2001
174
US
I would like to convert an Excel spreadsheet to csv.

...
Dim objExcel As Excel.Application

Set objExcel = New Excel.Application

objExcel.Workbooks.Open "C:\1.xls"
objExcel.ActiveWorkbook.SaveAs "C:\1.csv", xlCSV

objExcel.Quit
Set objExcel = Nothing
...

This does not seem to work.
Any ideas?

Thanks
 
In my application I wrote this function. It works. Change it for your needs:
Private Sub cmdFormate_Click()

Dim oXL As Excel.Application
Dim tempstr As String

' Start Excel and get Application object.
Set oXL = New Excel.Application
oXL.Visible = False
oXL.DisplayAlerts = False

oXL.Workbooks.Open FileName:= _
txtExcelDoc
oXL.ActiveWorkbook.SaveAs FileName:= _
"C:\temp\temp.csv", FileFormat:= _
xlCSV, CreateBackup:=False
oXL.ActiveWorkbook.Close

CleanFile ("C:\temp\temp.csv")

oXL.Workbooks.Open FileName:="C:\Temp\2.csv"
oXL.Selection.AutoFormat Format:=xlRangeAutoFormatList3, Number:=True, Font:= _
True, Alignment:=True, Border:=True, Pattern:=True, Width:=True
oXL.ActiveWorkbook.SaveAs FileName:="C:\Temp\TitlePTO_" & Replace(Replace(Now, "/", ""), ":", "") & ".xls", FileFormat:=xlExcel9795, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
oXL.ActiveWorkbook.Close

oXL.Quit
Set oXL = Nothing

Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.GetFile("C:\temp\1.csv")
MyFile.Delete
Set MyFile = fso.GetFile("C:\temp\2.csv")
MyFile.Delete
Set MyFile = fso.GetFile("C:\temp\temp.csv")
MyFile.Delete
Set fso = Nothing

RecName = tempstr1
MsgBox "Done"
End Sub
 
estherfin,

It works!

Many thanks.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top