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
    Posts
    11

    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")
    Clipboard.Clear
    With xlObject.ActiveWorkbook.ActiveSheet
    '.Range("A:A:k:k").

    .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.

    Thanks

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

    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
        Next
    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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

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