I need some help figuring out how to use VB6 to search an Excel spreadsheet for a string, and then determining what Cell that string resides in. I want to use a textbox to specify the string to search for. When it finds the string, I need to get the info from the cell right below it, and then display that info in a msgbox.
I'm new at using VB6 with excel, but I have figured out how to read from a specific cell, and how to write to a specific cell. I get a runtime error 91, when I run my app, but it's not a surprise to me since I don't know enough to make it work...but I did at least try.
I'm new at using VB6 with excel, but I have figured out how to read from a specific cell, and how to write to a specific cell. I get a runtime error 91, when I run my app, but it's not a surprise to me since I don't know enough to make it work...but I did at least try.
Code:
Private Sub cmdSearch_Click()
Dim xlApp As Excel.Application
Dim wb As Workbook
Dim ws As Worksheet
Set xlApp = New Excel.Application
Set wb = xlApp.Workbooks.Open("C:\users\JoeSmith\desktop\test.xls")
Set ws = wb.Worksheets("Sheet1") 'Specify your worksheet name
Range("A1:D5").Select 'How do I make it to where it searches all the cells, instead of having to tell it which ones to search?
Selection.Find(What:=txtSearch, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
xlApp.Quit
Set ws = Nothing
Set wb = Nothing
Set xlApp = Nothing
End Sub