Excel to VB

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Excel to VB

  1. #1
    Join Date
    Apr 2009

    Exclamation Excel to VB

    Hi all,

    What I am trying to do is search an excel document and bring back all results that matches my search critera.

    On a VB form I have a text box and a flexgrid.

    I want it to search for the text within my text box, and when it finds a match bring it into my flexgrid. (There maybe more than one result).

    I am using VB6 and have managed to coble together this code so far, but it just does not seem to work:

    Dim xlObject As Excel.Application
    Dim xlWB As Excel.Workbook
    Set xlObject = New Excel.Application
    Set xlWB = xlObject.Workbooks.Open("D:\test.xls")
    With xlObject.ActiveWorkbook.ActiveSheet

    .Cells.Find(What:=txtDate.Text, After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate

    End With

    End Sub

    If anyone has any ideas please let me know as i am a bit stumped.


  2. #2
    Join Date
    Mar 2009
    Italy - Breganze (VI)
    You can use Find in other way. See below code:

    With xlObject.Application.Range("A1:F9")
        Set c = .Find(What:=txtDate.Text, LookIn:=xlValues,_
                   SearchOrder:=xlByRows, SearchDirection:=xlNext)
        For Each c In [A1:F9]
            If c.Value = txtDate.Text Then
                Debug.Print c.Address & " : " & c.Value
            End If
    End With

Similar Threads

  1. EXCEL crash with VB DLL running on XP PRO SP2
    By flv58 in forum VB Classic
    Replies: 0
    Last Post: 02-09-2007, 07:24 AM
  2. Replies: 1
    Last Post: 01-02-2007, 09:58 AM
  3. vb to Excel and back to vb
    By bobbyboy in forum VB Classic
    Replies: 2
    Last Post: 10-11-2005, 09:34 AM
  4. Addressing Excel on screen from VB
    By dmb-job in forum VB Classic
    Replies: 0
    Last Post: 06-10-2005, 07:00 PM
  5. The day that everything went wrong!!!
    By WHYVB? in forum .NET
    Replies: 0
    Last Post: 10-03-2001, 10:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center