Export data [EXCEL] to CSV file

B

Brattex

Hi there

Apologies in advance if there's a more appropriate group for this, but
I figure "VBA and OFFICE" are valid enough for my query ;)

I've got an EXCEL spreadsheet which I'm coding underneath with the VBA
stuff, and I need to find a way to export the current sheet's important
parameters into a CSV file. I've successfully got it to export to a NEW
CSV file each time through butchering some code I found on the internet
[see below], but how can I get it to ADD to a CSV file that already
exists? I'd rather APPEND data to an existing file,so I can have
fifteen spreadsheets all exported to the same CSV file for future
manipulation.

Also, not sure if there's a quicker way to store twelve variables' data
to a CSV file than the way I've hard-coded it, so if there is, that'd
be great. Maybe I need to create a array... [thinking to myself]...

Thanks
Bryan

DestFile = InputBox("Enter the destination filename" _
& Chr(10) & "(with complete path):", "Quote-Comma Exporter")

FileNum = FreeFile()

Open DestFile For Output As #FileNum

Print #FileNum, """" & "Owner" & """";
Print #FileNum, ",";
Print #FileNum, """" & "OwnerContactNo" & """";
Print #FileNum, ",";
Print #FileNum, """" & "Address" & """";
Print #FileNum, ",";
Print #FileNum, """" & "Make" & """";

Close #FileNum
 
S

Steve Rindsberg

Off top of head:

Open DestFile For APPEND As #FileNum

(should append output to the specified file if it exists or create it and
append if not)

Brattex said:
Hi there

Apologies in advance if there's a more appropriate group for this, but
I figure "VBA and OFFICE" are valid enough for my query ;)

I've got an EXCEL spreadsheet which I'm coding underneath with the VBA
stuff, and I need to find a way to export the current sheet's important
parameters into a CSV file. I've successfully got it to export to a NEW
CSV file each time through butchering some code I found on the internet
[see below], but how can I get it to ADD to a CSV file that already
exists? I'd rather APPEND data to an existing file,so I can have
fifteen spreadsheets all exported to the same CSV file for future
manipulation.

Also, not sure if there's a quicker way to store twelve variables' data
to a CSV file than the way I've hard-coded it, so if there is, that'd
be great. Maybe I need to create a array... [thinking to myself]...

Thanks
Bryan

DestFile = InputBox("Enter the destination filename" _
& Chr(10) & "(with complete path):", "Quote-Comma Exporter")

FileNum = FreeFile()

Open DestFile For Output As #FileNum

Print #FileNum, """" & "Owner" & """";
Print #FileNum, ",";
Print #FileNum, """" & "OwnerContactNo" & """";
Print #FileNum, ",";
Print #FileNum, """" & "Address" & """";
Print #FileNum, ",";
Print #FileNum, """" & "Make" & """";

Close #FileNum
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top