VB.net Find method causing errors in another Excel document

I am getting   the error below when I run the following code in my VB.net Excel Add-in. The value is definitely there
and I can find it using the loop shown further down. What have I done wrong in my code?      

                  Dim xWorkBook As Microsoft.Office.Interop.Excel.Workbook
                    xWorkBook = xlApp.Workbooks.Open(oDetail3)
       oFindAddress = xWorkBook.ActiveSheet.Range("A1:A1048576").Find( _
           What:=oDetail5, After:=xWorkBook.Sheets(1).Range("A1"), _
           LookIn:=Excel.XlFindLookIn.xlValues, LookAt:=Excel.XlLookAt.xlPart, SearchOrder:=Excel.XlSearchOrder.xlByColumns, _


                     Dim strValue As String
                                    Dim blnThere As Boolean = False
                                    For r As Integer = 1 To 1000
                                        strValue = CStr(xWorkBook.Sheets(oUseSheet).cells(r, 1).value)
                                        If strValue = oDetail5 Then
                                            blnThere = True
                                            oListStartRow = r + 1
                                            Exit For
                                        End If
                                    If blnThere = True Then
                                        MsgBox("Not there")
                                    End If
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne Taylor (webtubbs)Commented:
try something like this...

Dim xWorkBook As Microsoft.Office.Interop.Excel.Workbook
Dim oFindRange As Microsoft.Office.Interop.Excel.Range
xWorkBook = xlApp.Workbooks.Open(oDetail3)
oFindRange = xWorkBook.ActiveSheet.Range("A:A").Find(What:=oDetail5, LookIn:=Excel.XlFindLookIn.xlValues, LookAt:=Excel.XlLookAt.xlPart)
If oFindRange IsNot Nothing Then
    oFindAddress = oFindRange.Address
    MessageBox.Show("'" & oDetail5 & "' not found in column 'A'")
End If

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.