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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using VB6 to change Excel workbook to CVS file 1

Status
Not open for further replies.

armylogman

Technical User
Feb 16, 2005
34
US
here is the code that I am using and I am not very good with VB6

Sub saveExcelAsCsv(DCRASRP.xls As String)

Dim objXlApp As New Excel.Application
Dim objXlBook As Excel.Workbook

' Setup the Excel Workbook to save
Set objXlBook = Excel.Workbooks.Open(DCRASRP.xls)

' Save the Excel file as a CSV file in a temp location
objXlBook.SaveAs "c:\reconnewxls\dcrasrp1.xls", xlCSVWindows


' Clean up
objXlBook.Close True ' Save changes
objXlApp.Quit ' Close Excel
Set objXlBook = Nothing
Set objXlApp = Nothing
End Sub

Any help would be greatly appreciated also when I run this it gives me an error on line 1 char 27.
 
DCRASRP.xls is not a valid variable name.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
As PHV said, DCRASRP.xls is not a valid variable name. Try something like this:
Code:
Sub saveExcelAsCsv(strFilename As String)
     
    Dim objXlApp As New Excel.Application    
    Dim objXlBook As Excel.Workbook
     
    ' Setup the Excel Workbook to save    
    Set objXlBook = Excel.Workbooks.Open(strFilename)
     
    ' Save the Excel file as a CSV file in a temp location    
    objXlBook.SaveAs "c:\reconnewxls\dcrasrp1.xls", xlCSVWindows
     

    ' Clean up    
    objXlBook.Close True    ' Save changes    
    objXlApp.Quit           ' Close Excel    
    Set objXlBook = Nothing    
    Set objXlApp = Nothing
End Sub
Something else you might want to look at is your objXlBook.SaveAs method. Your filename there ends with .xls which is an Excel format, but you're saving as .csv, so wouldn't you want your output name to be .csv?
 
Anyway, you've posted in a wrong forum: VB6 isn't VBS
 
Thanks,

I am sorry for the wrong post PHV i will be more careful next time.

also thanks to withanh it is going to work great like I said I am new to VB of anykind.

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top