Using EXCEL in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kushwaha2k
    New Member
    • Jun 2007
    • 3

    Using EXCEL in VB

    Hi,

    I want to copy data from EXCEL into FlexGrid in VB.

    Can any buddy help me. It is urgent.
  • eklavyavats
    New Member
    • May 2007
    • 24

    #2
    Originally posted by kushwaha2k
    Hi,

    I want to copy data from EXCEL into FlexGrid in VB.

    Can any buddy help me. It is urgent.

    Can you tell more details about your project like what is FlexGrid and what do you want to do in it? I am doing some similar kind of project so if you can tell me what are you doing i can help you a lot...

    Comment

    • kadghar
      Recognized Expert Top Contributor
      • Apr 2007
      • 1302

      #3
      Hi

      I hope this code helps, what it does is to put an Excel Range into a Strings Array in VB.
      The code is not very good since i dont remember if there's a way to asign a range into an array without a FOR (but you can find it out in some forum... yeah right...)

      [CODE=vb]Sub Hola()
      Dim i As Long
      Dim j As Integer
      Dim MaxRow As Long
      Dim MaxCol As Integer
      Dim Obj1 As Object
      Dim mStr1() As String

      MaxRow = 10
      MaxCol = 10

      ReDim mStr1(MaxRow, MaxCol) As String
      With Application.Fil eDialog(msoFile DialogFilePicke r)
      .AllowMultiSele ct = True
      .Filters.Clear
      .Filters.Add "Excel Files (*.xls)", "*.xls"
      .Show
      If .SelectedItems. Count > 0 Then
      Set Obj1 = CreateObject("e xcel.applicatio n")
      Obj1.Workbooks. Open (.SelectedItems .Item(1))
      End If
      End With
      For i = 1 To MaxRow
      For j = 1 To MaxCol
      mStr1(i, j) = Obj1.Worksheets (1).Cells(i, j)
      Next
      Next
      End Sub[/CODE]

      oh, by the way, you can add a line to see the excel worksheet and then close it or something like :

      obj1.visible=tr ue
      or
      obj1.activework book.close savechanges:=fa lse

      Good Luck!

      Comment

      • kushwaha2k
        New Member
        • Jun 2007
        • 3

        #4
        Thanks a lot 4 such efforts. I have done using your given help.

        Originally posted by kadghar
        Hi

        I hope this code helps, what it does is to put an Excel Range into a Strings Array in VB.
        The code is not very good since i dont remember if there's a way to asign a range into an array without a FOR (but you can find it out in some forum... yeah right...)

        [CODE=vb]Sub Hola()
        Dim i As Long
        Dim j As Integer
        Dim MaxRow As Long
        Dim MaxCol As Integer
        Dim Obj1 As Object
        Dim mStr1() As String

        MaxRow = 10
        MaxCol = 10

        ReDim mStr1(MaxRow, MaxCol) As String
        With Application.Fil eDialog(msoFile DialogFilePicke r)
        .AllowMultiSele ct = True
        .Filters.Clear
        .Filters.Add "Excel Files (*.xls)", "*.xls"
        .Show
        If .SelectedItems. Count > 0 Then
        Set Obj1 = CreateObject("e xcel.applicatio n")
        Obj1.Workbooks. Open (.SelectedItems .Item(1))
        End If
        End With
        For i = 1 To MaxRow
        For j = 1 To MaxCol
        mStr1(i, j) = Obj1.Worksheets (1).Cells(i, j)
        Next
        Next
        End Sub[/CODE]

        oh, by the way, you can add a line to see the excel worksheet and then close it or something like :

        obj1.visible=tr ue
        or
        obj1.activework book.close savechanges:=fa lse

        Good Luck!

        Comment

        Working...