×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Save xls file to cvs file

Save xls file to cvs file

Save xls file to cvs file

(OP)
I am trying to write VBScript to save an active Excel file as a CVS file, The format of the Excel file needs to be retained.
See example Excel file (57094-97_B_Op 2 of 2_03-04-24_3.xls) and example CVS file (57094-97_B_Op 2 of 2_03-04-24_3.cvs) for comparing.

The Excel file is from a CMM Software called, Calypso. You will get the standard "SECURITY WARNING Macros have been disabled." when opened. It seems the macros from the template that generates the Excel file gets carried over.

Back to my question.
I am failing to save the xls file in the script as a cvs file.

CODE --> VBScript

Dim objXL, strMessage

On Error Resume Next

Set objXL = GetObject(,"Excel.Application")

If Not TypeName(objXL) = "Empty" then
Const xlCSV=6
    'strMessage = "Excel Running"    
	src_file = objXL.ActiveWorkbook.Name
	'msgbox src_file 'for testing
		'New
		dest_file = Replace(Replace(src_file,".xlsx",".csv"),".xls",".csv")
		
		src_file.SaveAs "C:\Users\Public\Documents\Zeiss\CALYPSO 7.4\workarea\results\Excel Files" & "\" & dest_file, xlCSV
		msgbox dest_file 'for testing
		msgbox src_file 'for testing

		src_file.Close False
		objXL.Quit
		'End New
Else 
    MsgBox "No active Excel file open."
End If 

Any help is appreciated.

Rick Stanich
CMM Programming and Consulting, LLC

RE: Save xls file to cvs file

You need to work with Excel workbook instead of its name:

If Not TypeName(objXL) = "Empty" then
    Const xlCSV=6
    Set objWbk = objXL.ActiveWorkbook ' may require additional test before to check if a workbook is open
    src_file = objWbk.Name
    'msgbox src_file 'for testing
    'New
    dest_file = Replace(Replace(src_file,".xlsx",".csv"),".xls",".csv")

    objWbk.SaveAs "C:\Users\Public\Documents\Zeiss\CALYPSO 7.4\workarea\results\Excel Files" & "\" & dest_file, xlCSV
    msgbox dest_file 'for testing
    msgbox src_file 'for testing

    objWbk.Close False 

combo

RE: Save xls file to cvs file

(OP)
Workbook instead of name....
Got it!
Worked fine with your code.
Solved.

Thank you.

Rick Stanich
CMM Programming and Consulting, LLC

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close