WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Excel
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Save XLS file as a CSV file

Keywords: 	  SaveAs XLS CSV file xlCSV

Question:

I am trying to programmatically change an excel document to an CSV document.

I am using
SaveAs(:: Filename="c:\temp\test.csv")

How can I add the fileformat to this.

the VB for this is ActiveWorkbook.SaveAs FileName:="C:\DealerServer\Excel\myTest.csv", FileFormat:=xlCSV, CreateBackup:=False

Thank you in advance for any help.

Answer:

OLE functions support named parameters. The syntax structure is:

Object.Method(p1, p2 :: n3 = v3, n4 = v4)

Positional parameters (shown as p1 and p2), if any, come first, followed by a double colon ("::"), and then any named parameters (n3 and n4). Each named parameter is followed by an equals sign ("=") and then the value for the parameter (v3 and v4). Whitespace is ignored.

Here are some examples:

; 2 positional parameters
Application.InputBox("My Prompt", "My Title")

; 2 positional parameters and 2 named parameters
Application.InputBox("My Prompt", "My Title" :: Left = 40, Top = 300)

; no positional parameters and 2 named parameters
;(note the leading colon)
Application.InputBox(:: Prompt = "My Prompt", Title = "My Title")

Here is some sample code.....

source_xls = "C:\WINDOWS\DESKTOP\testnum.xls" 
ExcelWS = ObjectOpen("Excel.Application")
EWS = ExcelWS.Application
EWS.visible = @true
EWB = EWS.Workbooks
EWB.Open (source_xls)
xlCSV = 6 ; an Excel constant value for the file format xlCSV.	  
WBA = ExcelWS.ActiveWorkbook
WBA.SaveAs(::FileName="C:\windows\desktop\myTest.csv",FileFormat=%xlCSV%,CreateBackup=0)



Article ID:   W14699
Filename:   Save XLS file as a CSV file.txt
File Created: 2000:10:26:15:01:56
Last Updated: 2000:10:26:15:01:56