CSV File

  • Thread starter Thread starter Charles A. Lackman
  • Start date Start date
C

Charles A. Lackman

Hello,

I have been able to successfully make an Excel file from data I have in a
dataset, IE:

With Excel
..SheetsInNewWorkbook = 1
..Workbooks.Add(1)
..Worksheets().Select()
For intRow = 0 To FedExDataset.Tables("Order").Rows.Count - 1
For intColumnValue = 0 To FedExDataset.Tables("Order").Columns.Count - 1
..Cells(intRow + 1, intColumnValue + 1).Value =
FedExDataset.Tables("Order").Rows(intRow).ItemArray(intColumnValue).ToString
Next
Next
strExcelFile = "C:\Customers\" & TheFileName
..ActiveWorkbook().SaveAs(strExcelFile)
..ActiveWorkbook.Close()
Exit Sub

What I am trying to do is make the file into a CSV.
".ActiveWorkbook().SaveAs(strExcelFile)" has a parameter for fileformat, but
i cannot get it to work properly. IE:

Dim TheFormat As New Excel.XlFileFormat
TheFormat = Excel.XlFileFormat.xlCSV
..ActiveWorkbook().SaveAs(strExcelFile, TheFormat)

Any Suggestions??
Thanks,
Chuck
 
Yes I receive an error:

System.MissingMemberException: Public member 'XlFileFormat' on type
'ApplicationClass' not found. at
Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type
objType, String name, Object[] args, String[] paramnames, Boolean[]
CopyBack) at CKMemoriesOrderSite.VerifyOrder.btnSubmit_Click(Object sender,
EventArgs e)

Chuck

"Kim Greenlee" <kim at digipede dot net> wrote in message
When you say that you can't get it to work properly what does that mean? Is
a file being created at all? Is the format wrong? Is the SaveAs()
returning an error?

Thanks,

Kim Greenlee
blog http://krgreenlee.blogspot.com
 
Thank you for your help.

When I changed the code to what you suggested below, I received the
following exception:

An Error Has Occurred: System.MissingMemberException: Public member
'Constants' on type 'ApplicationClass' not found.

Thanks,

Chuck


Chuck,

Try using: Excel.Constants.XlFileFormat.xlCSV

Thanks,

Kim Greenlee
blog http://krgreenlee.blogspot.com
 
Hello,

I got the following to work.

Dim TheFormat As New Excel.XlFileFormat
TheFormat = Excel.Application.DefaultSaveFormat.xlCSV
..ActiveWorkbook().SaveAs(strExcelFile, TheFormat)
..ActiveWorkbook.Close()

Unfortunatelly, when I call the last line of code .ActiveWorkbook.Close()
it basically freezes. If I comment out the code it works ok, but locks the
document to readonly.

Any suggestions is greatly appreciated.

Thanks Kim,

Chuk
 
Back
Top