Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Automate Excel export to a CSV file

Hi...

I'm wondering if it's possible to export an excel file to a csv file via
script. I have data in excel that I need to import into a SQL Server
database, but importing the excel spreadsheet results in missing data or
values that are assigned to null when they have a value in the spreadsheet.
If I convert the excel spreadsheet to a csv and import the csv, it works fine.

I know the users of the spreadsheet can export/save as a csv file, I'd
rather automate this process rather than relying on them to actually do this
themselves. Is this at all possible?
--
Chris Burke
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Automate Excel export to a CSV file

Yes you can. I have data in two columns, A has field names and B has values
and use this code which is a modified version of something I got off this
forum:


' Write data to CSV file

Set fswrite = CreateObject("Scripting.FileSystemObject")
'Set path names
CSVPathName = FPath + WriteFileName + ".csv"
DocPathName = FPath + WriteFileName + ".doc"

' Open and export data to CSV File
fswrite.CreateTextFile CSVPathName
Set fwrite = fswrite.GetFile(CSVPathName)
Set tswrite = fwrite.OpenAsTextStream(ForWriting, TristateUseDefault)

LastRow = z + 1
LastCol = 2
With Sheets("Data Table2")
For ColCount = 1 To LastCol
OutputLine = ""
For RowCount = 2 To LastRow
If OutputLine = "" Then
OutputLine = Cells(RowCount, ColCount).Value
'MsgBox "OutputLine = " & OutputLine
Else
'If ColCount = 2 Then MsgBox RowCount & ": " & Cells(RowCount,
ColCount).Value
OutputLine = OutputLine & Delimiter & Cells(RowCount,
ColCount).Value
End If
Next RowCount
tswrite.writeline OutputLine
Next ColCount
End With
tswrite.Close
MsgBox "CSV has been written!"

--
Hope it helps,
Andy


"Chris B" wrote:

Hi...

I'm wondering if it's possible to export an excel file to a csv file via
script. I have data in excel that I need to import into a SQL Server
database, but importing the excel spreadsheet results in missing data or
values that are assigned to null when they have a value in the spreadsheet.
If I convert the excel spreadsheet to a csv and import the csv, it works fine.

I know the users of the spreadsheet can export/save as a csv file, I'd
rather automate this process rather than relying on them to actually do this
themselves. Is this at all possible?
--
Chris Burke

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to automate excel file sending by outlook from within the file Adrian Excel Discussion (Misc queries) 1 September 12th 08 01:59 PM
Automate export to a new workbook atledreier Excel Discussion (Misc queries) 0 July 5th 07 07:25 AM
Automate Import/Export Steve Excel Discussion (Misc queries) 0 October 14th 05 06:38 PM
Automate Export from Form Template to Seperate Table QuestDave Excel Discussion (Misc queries) 0 August 31st 05 05:25 PM
How do I automate upload of data from one excel file to another? RB Excel Worksheet Functions 1 May 11th 05 03:12 PM


All times are GMT +1. The time now is 07:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"