Hello friends!
My question is, how I can read information from different cells and different sheet's of Ms. Excel to the VB 6.0 Program.
For example, I need to read cell A1 located on Sheet "Sheet1" and cell B2 from "Sheet2"
Hello friends!
My question is, how I can read information from different cells and different sheet's of Ms. Excel to the VB 6.0 Program.
For example, I need to read cell A1 located on Sheet "Sheet1" and cell B2 from "Sheet2"
'This will give you the value stored in Cell A1 on Sheet "Sheet1"
Sheets("Sheet1").Range("A1").Value
Similarly
'This will give you the value stored in Cell B2 on Sheet "Sheet2"
Sheets("Sheet2").Range("B2").Value
You have to use this code to get the data from Excel. Hope this will help you.
Private Sub Command4_Click()
Dim oXLApp As Object
Dim oXlBook As Object
Dim oXLSheet As Object
Dim oXLRange As Object
Dim oXLCells As Object
Text1.Text = ""
Set oXLApp = GetObject("", "Excel.Application")
' oXLApp.Visible = True
Set oXlBook = oXLApp.Workbooks.open("MyExcelBook.xls")
Set oXLSheet = oXlBook.WorkSheets
oXLSheet("Sheet1").Select
Set oXLRange = oXLApp.range("A1")
' oXLRange("7").Select 'Put focus on cell A7.
Text1.Text = oXLRange("1").Value & vbCrLf
oXLSheet("Sheet2").Select
Set oXLRange = oXLApp.range("B1")
oXLRange("2").Select
Text1.Text = Text1.Text & oXLRange("2").Value
Set oXLCells = Nothing
Set oXLRange = Nothing
Set oXLSheet = Nothing
Set oXlBook = Nothing
oXLApp.Quit
Set oXLApp = Nothing
End Sub
Bookmarks