Results 1 to 3 of 3

Thread: Read information from Excel to VB

  1. #1
    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"

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    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

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    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

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,640,391.28509 seconds with 16 queries