CodeItBetter Programming Another VB Programming Blog

How to Read Excel Data

Posted on June 30, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'MS Office - How to Read Excel Data
'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
Filed under: MS Office Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.