Releasing Range Object

K

Kart

Hello,
I m new to Excel Programming, I was trying to Release the Range
Object that I got using the below code,

Excel.Range oRange; //Decl

oRange = (Excel.Range)m_oWorkSheet.Cells.Find(strSearchFor,
m_oWorkSheet.Cells[nHeaderRow, iter], Excel.XlFindLookIn.xlValues,
Excel.XlLookAt.xlWhole,
m_objOpt, Excel.XlSearchDirection.xlNext, false, m_objOpt, m_objOpt); //Get
Range Object

Marshal.ReleaseComObject(oRange); //Release Range Object

My Problem is when I get Range Object in the above specified way Excel
Instance keep running afte releasing other COM Object.

If I get it using below specified way Excel Instance is killed
at the end.
"oRange.get_Range(strStartRng, strStartRng)"

Is there any other way to release the Range Object?
Thanks in Advance.
 
G

Gary''s Student

Within Excel, the range is releaseable if it set to Nothing:

Sub dural()
Dim r As Range
Set r = Range("A1")
MsgBox (r.Address)
Set r = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top