By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,680 Members | 1,578 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,680 IT Pros & Developers. It's quick & easy.

cannot terminate excel process

P: n/a
I have struggled with this problem and the solution is that you have to
declare a variable for each and every object or collection within the
Excel application that you want to use:

For example:
Dim oExcel As Excel.Application = New Excel.Application

Dim lWorkBooks As Excel.Workbooks = oExcel.Workbooks
Dim lWorkBook As Excel.Workbook = lWorkBooks.Add()
Dim lWorkSheet As Excel.Worksheet = oExcel.ActiveSheet
Dim lCells As Excel.Range = lWorkSheet.Cells

Dim lCell As Excel.Range
Dim lRow As Excel.Range

lCell = lCells(1, 1)
lRow = lCell .EntireRow
lFont = lRow.Font
lFont.Bold = True
lFont.Size = 14

You will notice that you even have to declare a variable for the font
of a particular cell. I have tested this and it is necessary.

When you want to re-use a variable, you have to ReleaseComObject on it
first and then set it to nothing, otherwise......process gets locked

Even setting edit ranges:

Dim lProtection As Excel.Protection
Dim lAllowEditRange As Excel.AllowEditRange
Dim lAllowEditRanges As Excel.AllowEditRanges

lRange = lWorkSheet.Range(lStartCell, lEndCell)
lProtection = lWorkSheet.Protection
lAllowEditRanges = lProtection.AllowEditRanges
lAllowEditRange = lAllowEditRanges.Add("edit_range_1",

And then of course every single variable needs to be released with
ReleaseComObject and then set to nothing, otherwise....process gets
locked up.

And dont forget:
You have to love COM

Aug 17 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.