Home > How-To Library > MS Office
How to Read Excel Data
**************************************************************** * © 2007 CodeItBetter http://www.codeitbetter.com * * This notice MUST stay intact for legal use * **************************************************************** 'Declarations: 'Lib Reference: Microsoft Excel 11.0 Object Library 'If u not found 11.0 u can fined lower version 'Dim WithEvents xlBook As Excel.Workbook 'Declare it on Top 'Code: ' Write This in Any command button 'Here U mention ur Excel File name Set xlBook = GetObject(App.Path & "\SampleData.xls") xlBook.Application.Visible = True xlBook.Windows(1).Visible = True xlBook.Application.WindowState = xlMinimized Dim irow As Integer Dim jcol As Integer 'There r 3 rows X 3 columns in excel sheet For irow = 2 To 4 For icol = 1 To 3 MsgBox xlBook.Worksheets(1).Cells(irow, icol).Value Next Next 'Create this is an excel sheet and We have rows and ' colums like this Data is started from 2nd row so we 'mentioned in First for loop starts from 2 to till 4 ' 1st col 2nd col 3rd col ' sno name sal 1st row ' 1 Test1 223 2nd row ' 2 Test2 223 3rd row ' 3 Test3 223 4th row
If you would like to submit your code here please us. Do not forget to mention your name. We are always thankful to each and everyone of you who submitted their code here.