VB 6.0 - Getting data into Excel
Asked By Joe Lewis on 16-May-12 07:30 PM

I wrote a small VB program that writes a simple text file 1000 lines long, and each line has 50 numbers (or words) separated by commas. I then have an Excel spreadsheet that I put this data into. I go into a particular "data input" sheet, in cell A3 let's say, and I do the Data - Get Data stuff. When the window about the "tab" vs. "comma" delimiting comes up, I switch it from tab to comma. When I finish with all that, the data populates 50 columns (each with 1000 rows) on that sheet beautifully. My other sheets each have a dedicated column that reads the corresponding column on this "data input sheet".
My first question may best be asked on the Excel forum, but I want to know if there's a way to change all the default radio buttons in that Data-Get Data process? Like "Save Query Definition", comma delimited vs. tab delimited, and a couple other things. I want my master spreadsheet to bring up the proper defaults.
More importantly, back in my little VB6 program (which created the 1000 line text file), I would REALLY like to add some code that goes ahead and puts that text file into the "data input sheet" of the Excel spreadsheet (to replace the manual stuff I described above). Would this be that difficult to do (I'm hoping it is relatively easy, or at least quite possible)? Can anyone help me with this? Thanks a lot.
wally eye replied to Joe Lewis on 17-May-12 10:47 PM
Have you tried using the object model to push it to Excel? Something like
public sub PushToExcel(byval strPath as string, strWorksheet as string, strCell as string)
Dim newExcelApp As Excel.Application
Dim newWbk As Excel.Workbook
Dim newWkSheet As Excel.Worksheet
Set newExcelApp = Excel.Application
Set newWbk = newExcelApp.Workbooks.open(strpath)
Set newWkSheet = newWbk.Worksheets(strworksheet)
newwksheet.Range(strcell).resize(ubound(arrData), ubound(arrData,2)) = arrData
newwbk.save false
newwbk.close
newexcelapp.quit
set newwksheet = nothing
set newwbk = nothing
set newexcelapp = nothing
end sub
I'm doing this without testing, so there might be some errors. It assumes you have an array of data to push to a spreadsheet, 1000 rows by 50 columns should easily be handled by the routine.
wally eye replied to wally eye on 18-May-12 10:16 AM
And yes, I forgot to mention you need to set a reference to Excel (Tools, References from the VBA window)
hai. . please send me code for WRITING DATAGRID TO EXCELL FILE USING VB 6.0. . URGENT thanks and regards rajesh. Hi, refer link http: / / support.microsoft.com / kb
Hello Friends, I am using VB 6.0. and I would like to export my data's into EXCEL spread sheets. so
Hello Friends, I am using VB 6.0. and I would like to export my data's into EXCEL spread sheets. so
Hi Can we use VB 6.0 for navigating, querying and midifying excel files the same way we can update
Hi friends I am working on a VB 6.0 application which opens, unprotects, checks, modifies and then again protects the excel 97
end of post Why don't you just use the Excel COM library from within your vb app? Search on Excel.Application in google for samples
Hi folks, I have already had format my machine cd and installed my old and good application vb6. When i generate a report from vb is ok. But when a click in export report to excel, it generate a file but it is 0 kb!!!! Why?? What should i do . Thanks
Hello, I am trying to do some data filtering integrate all things into a sql line and execute it: (1) Select entire table from excel worksheet (2) Remove the rows in the table corresponding to duplicates in the CustomerNo column (3) Remove the blank lines in the excel file (where there is no CustomerNo) I have found a way to execute (1) and
Hi, I need to read some records from an excel file. I must get the name of the excel file from the user during the
Hello Friends. This is Kiran When ever i am exporting the data from Flex Grid or List View to Excel Sheet, By default it is taking the Format Cells to General . But for me it