-
Hi Vb-World:
I have a program that makes a report in text file, it has data like a table with colums and rows, i need to export it to Excel any version, how can i do that?, is there some API or function or method in VB to export from text to Excel?
Thanks in advance.
Best Regards.
-
Probably the easiest way is to open your text file from Excel and then save your resultant spreadsheet as an Excel format. For the sake of learning a thing or two, before you open your text file report, put yourself in "record macro" mode. If you want to get really snooty, you could alternately use Data|Get External Data|Create New Query and use the text ISAM (if you have it installed). Hope this helps :)
-
Well ....
Seems people are turning to VB-Office combination for a change!
I have already tried to help one with VB-Word, am in the process of helping another with the same, and can do VB-Excel for you. The thing is I have to type out the entire code and mail it. This will take time, and you may have to wait for a week or so, as I do it from my home. I am picking up the samples from a book named something like 'Developing Client-Server Applications with VB 5'. There is an updated version of the book with VB 6. If you can get hold of that book, it will more than solve your problem. If not, mail me at [email protected] and wait for at least a week.
I received thanks from the fellow, but I don't know whether it came from the heart or the mind (sincerely or politely!) I hope it is the former one.
-
Format and save your file as a .csv Then if you open the file it will load into Excel.
:)
-
This is just off the top of my head, but the easiest way to do what you are thinking is to create you text file in a comma delimited format:
ex. Header1,header2,header3,header4,
data1,data2,data3,data4
And save the text file with a .csv extension.
And now if I remember right, to import this bad boy into excel, all you have to do is set a reference to the excel object library and then type in the following code (this only imports the data into an excel sheet and does nothing else, but once there, you can do much):
Code:
Dim ExcelApp as Excel.Application
Dim ExcelBook as Excel.Workbook
Dim ExcelSheet as Excel.WorkSheet
Private sub CreateExcelObject(ByVal sFileName as string)
Set ExcelApp=New Excel.Application
Set ExcelBook=ExcelApp.workbooks.open(sFilename)
'Set the active sheet. This will be the object that you will call if you need to manipulate the worksheet.
Set ExcelSheet=ExcelApp.ActiveSheet
End sub
Private sub Command1_Click
Call CreateExcelObjects(Text1.Text)
ExcelApp.Visible=True
End sub
Private sub Form_Unload()
'Set you objects equal to nothing, and close excel if you are doing all your work through code.
ExcelApp.Quit
'Here you might see Dialog boxes if you did not save before this. You save using:
'ExcelApp.SaveWorkSpace(Filename)
'I think.
Set ExcelSheet=Nothing
Set ExcelBook=Nothing
Set ExcelApp=Nothing
End sub
Hope this helps.
-
I want to thank to each one your post's, i take the frank and reeset solution, in fact i discover the meaning of .csv files and i can use the same way with tabs in a text files.
Thanks again.
Best regards.
-
AM LOPEZ,
.csv = Comma Separated Values
as reeset wrote
Header1,header2,header3,header4,
data1,data2,data3,data4
or
"Header1","header2","header3","header4"
"data1","data2","data3","data4"
:):)