Click here to Skip to main content
15,912,756 members

Comments by arpita aradhya (Top 2 by date)

arpita aradhya 23-Nov-16 6:27am View    
I have improved the code and edit the code in the post. Now I have error at line xlFile_WB = xlappFile.Workbooks(destination1). system nullreferenceexception object reference not set
arpita aradhya 23-Nov-16 5:42am View    
Deleted
Hi,

I have added all that but it does not identify lookin, lookwhole like inb excel

Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click

Dim xlappFile As Excel.Application = Nothing
Dim xlFile_WB As Excel.Workbook = Nothing
Dim xlFile_WS As Excel.Worksheet = Nothing
Dim xlFirstfile_WS1 As Excel.Worksheet = Nothing
Dim FoundRange As Excel.Range
Dim searchID As String
searchID = Textbox1.Text

Try
xlFile_WB = xlappFile.Workbooks(destination1) ' destination1 is selected by 'user
xlFile_WS = xlappFile.Worksheets(1)
FoundRange = xlFile_WS.Cells.Find(What:=searchID, LookIn:=xlFormulas, LookAt:=xlWhole)

If FoundRange Is Nothing Then
textbox2.Text = "not found"
textbox3.Text = "not found"
textbox4.Text = "not found"
textbox5.Text = "not found"
textbox6.Text = "not found"
Else
textbox2.Text = FoundRange.Offset(0, 2).Value
textbox3.Text = FoundRange.Offset(0, 3).Value
textbox4.Text = FoundRange.Offset(0, 4).Value
textbox5.Text = FoundRange.Offset(0, 5).Value
textbox6.Text = FoundRange.Offset(0, 6).Value
End If
Catch ex As Exception
MsgBox(ex.ToString)
Finally
Me.Close()
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
ReleaseObject(xlFile_WS)
xlFile_WB.Close(SaveChanges:=False)
ReleaseObject(xlFile_WB)
xlappFile.Quit()
ReleaseObject(xlappFile)
End Try
End Sub
Private Sub ReleaseObject(ByVal ob As Object)

Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(ob)
Catch
Finally
ob = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
End Try
End Sub