I am able to create .xlw files that will open with Microsoft Excel, but is there a way to turn that into a .csv file? The code I use to create the .xlw file is as follows:

Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add
    Set oSheet = oBook.Worksheets(1)
    oSheet.Range("A1").Value = LastName.Text & "_" & FirstName.Text & "_" & Last4.Text
    oSheet.Range("B1").Value = Phase.Text
    oSheet.Range("C1").Value = DS.Text
    oSheet.Range("D1").Value = RoomNumber.Text
    oSheet.Range("E1").Value = "Destination"
    oSheet.Range("F1").Value = "LB1"
    oSheet.Range("G1").Value = "LB2"
    oSheet.Range("H1").Value = "DTOUT"
    oSheet.Range("I1").Value = "DTIN"

oBook.SaveAs "C:\Documents and Settings\Brooks\Desktop\Duh\" & LastName.Text & "_" & FirstName.Text
oExcel.Quit

As I said, this will create a .xlw file with no problem that will run fine in Excel, but it would be a lot easier to modify later in the program if it were a csv file. Any Suggestions?

Thanks in advance!

Ok, after a little tinkering, I figured it out myself. Now, having seen how many people have looked at this post, below is the code I used. (In case anyone else is having the same issue)

Dim FileName As String

FileName = "C:Folder\File.csv"
Open FileName For Output As #1
Print #1, Info.Text
Close #1

The line of code that opens the "FileName" for output will actually create the file in the specified file destination, which you could add a common dialog function to handle. Either way, the only thing you need to do to create the .csv file is instead of putting .txt to create a text file, put .csv. This method does work fine, and will open in Microsoft Excel perfectly.

hi I'd like to ask a question. Your coding in the conversion to an xls file was invaluable, but I'd like to know how it would be possible to read from an entire database and have been having some problems. can you give me any insight on this? This is a project for my end-of year examinations. thank you very much.

Regards,

Agyei

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.