Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to write a csv file?

Status
Not open for further replies.

apascual

Programmer
Jun 17, 2003
11
PH
help! how will i write a csv file format using visual basic? data will be coming form sql tables.

can anyone send me a source code? tnx in advance.
 
Either use the filesystemobject (common to all ms office object models) or use open filename for [append|output] as #filenumber.

Try digging around in teh VBA help files.

 
Hi,

try this

Sub CreateAfile()
Dim str As String

Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\testfile.txt", True)

str = Worksheets("Sheet1").Cells(6, 3).Value & ", " & Worksheets("Sheet1").Cells(6, 4).Value
a.WriteLine (str)
a.Close
End Sub

I've taken this from the help of VBA.

hope this will help

A
 
saves the active sheet....you can splice variables into the path and file name to make it more dynamic.



ActiveWorkbook.SaveAs Filename:= _
"C:\my_path\file_name.csv", FileFormat:=xlCSV, _
CreateBackup:=False
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top