Select data from different worksheet

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nairda
    New Member
    • May 2007
    • 39

    Select data from different worksheet

    Hi,
    I'm working with VB 6 and Ms Excel. My Excel Workbook has 3 worksheets.
    I want to retrieve data from one of the sheets and show it in my Flexgrid, but I don't know how to select a spesific sheet.

    I've wrote this code so far:
    Code:
        Dim xlapp As Excel.Application
        Dim xlbook As Excel.Workbook
    Private Sub Command1_Click()
        Set xlapp = New Excel.Application
        Set xlbook = xlapp.Workbooks.Open("C:\XLTAB.xls")
        XL
    End Sub
    Code:
    Private Sub XL()  
        Clipboard.Clear
        With xlapp.ActiveWorkbook.ActiveSheet  '------> I think I miss something here
            .Range("A2:K284").Copy
        End With
        
        With MSHFlexGrid1
            .Redraw = False
            .Row = 3
            .Col = 2
            .RowSel = MSHFlexGrid1.Rows - 1
            .ColSel = MSHFlexGrid1.Cols - 1
            .Clip = Replace(Clipboard.GetText, vbNewLine, vbCr)
            .Col = 1
            .Redraw = True
        End With
        
        xlapp.DisplayAlerts = False
        xlbook.Close
        xlapp.Application.Quit
        Set xlbook = Nothing
        Set xlapp = Nothing
    End Sub
    Please help.

    Nairda
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    I think rather than .ActiveSheet you refer to .Sheets("nameof sheet") or .Sheets(numbero fsheet).

    Comment

    • nairda
      New Member
      • May 2007
      • 39

      #3
      Originally posted by Killer42
      I think rather than .ActiveSheet you refer to .Sheets("nameof sheet") or .Sheets(numbero fsheet).

      Ok, thank you.
      It's working great.

      Nairda

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Glad we could help. :)

        Comment

        Working...