How to go about in Importing Excel data into a grid?
Good afternoon :wave:
I would like to import data from an Excel file and fill a grid with the data. Any ideas on how to do it?
I would also like to import text from an external source, something like a txt file and import it in to a grid.
eg If I was to copy 20 rows of text, from either an excel file or a txt file and copy it into a grid. Is there a way for the data to be placed into the grid?
I am a novice at Vb6 so any help will be much appreciated. Thank you.
Re: How to go about in Importing Excel data into a grid?
Welcome to the Forums.
One way would be to have a loop that went through the used range in Excel and place each value in the grid.
VB Code:
Dim oApp as excel.application
dim oWB as excel.workbook
dim iRow as integer
dim iCol as integer
set oapp = new excel.application
set owb = oapp.workbooks.open("C:\Book1.xls")
irow = owb.cells.range.specialcells(xlCellTypeLastCell).Row
icol = owb.cells.range.specialcells(xlCellTypeLastCell).Column
'Todo: loop though the row/columns adding the cells(irow, icol).Value to each cell in your grid.
Re: How to go about in Importing Excel data into a grid?
G'day RobDog888.
That makes alot of sense, I havent tried it but it looks like it should work. Brilliant!! :thumb:
Re: How to go about in Importing Excel data into a grid?
Thanks, there are a couple of other more complex methods that may be better if your coping allot of records.
Post back if you have any problems with this. :thumb: