Atchoum wrote:
Thanks. I am at a loss here...
Atchoum
Here we are... I've tested this code. Notice that whenever an object might
be returned, I keep it in a variable so I can dispose of it...
e.g. Workbooks.Sheets(1).Range(1, 1) involves three objects. You should
declare a variable for each...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
* * * * Dim oExcel As Excel.Application = New Excel.Application
* * * * Dim oWorkbooks As Excel.Workbooks = oExcel.Workbooks
* * * * Dim oWorkbook As Excel.Workbook =
oWorkbooks.Open(Application.StartupPath & "\test.xls", Editable:=True)
* * * * Dim oSheets As Excel.Sheets = oWorkbook.Sheets
* * * * Dim oRange As Excel.Range
* * * * Dim oSheet As Excel.Worksheet
* * * * Dim s As Excel.Range
* * * * Dim nextS As Excel.Range
* * * * Dim sFirstAddress As String
* * * * Dim i As Integer
* * * * For i = 1 To oSheets.Count
* * * * * * oSheet = CType(oSheets(i), Excel.Worksheet)
* * * * * * oRange = oSheet.UsedRange
* * * * * * s = oRange.Find("[[C:", lookin:=-4163) 'xlValues
* * * * * * If Not s Is Nothing Then
* * * * * * * * sFirstAddress = s.Address
* * * * * * * * Do
* * * * * * * * * * nextS = oRange.FindNext(s)
* * * * * * * * * * NAR(s)
* * * * * * * * * * s = nextS
* * * * * * * * Loop While Not s Is Nothing And s.Address <> sFirstAddress
* * * * * * End If
* * * * * * NAR(oRange)
* * * * * * NAR(oSheet)
* * * * Next i
* * * * oExcel.Visible = True
* * * * NAR(oSheets)
* * * * NAR(oWorkbook)
* * * * NAR(oWorkbooks)
* * * * NAR(oExcel)
* * End Sub
* * Private Sub NAR(ByVal o As Object)
* * * * Try
* * * * * * System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
* * * * Finally
* * * * * * o = Nothing
* * * * End Try
* * End Sub
Let me know if it worked!