Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 06-01-2009
Member
 
Join Date: Dec 2008
Posts: 13
Read information from Excel to VB

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"
Reply With Quote
  #2  
Old 06-01-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: Read information from Excel to VB

'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
Reply With Quote
  #3  
Old 06-01-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: Read information from Excel to VB

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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Read information from Excel to VB"
Thread Thread Starter Forum Replies Last Post
How to make Excel VBA Read Only Sayam Software Development 7 21-12-2012 11:21 AM
How to read Text File in Excel via VBA Rish!On MS Office Support 7 02-02-2012 04:51 PM
How to read Excel (xls file) From C# KornFlexia MS Office Support 3 16-12-2010 08:24 AM
How to read and write Excel files in PHP ? Sudra Software Development 3 06-05-2009 05:18 PM
Excel is unable to read file Logan.M Software Development 4 08-04-2009 10:29 AM


All times are GMT +5.5. The time now is 09:44 PM.