473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Accessing parents of linked cells in Excel without COMException

Hi,

I am trying to obtain the column number of the parent of a cell, if
the cell is a linked cell (i.e. its value depends on another cells
value).

I try to read "Precedents"(parent cells) of a "Range"(selection of a
single cell in this case) for each cell in my table to access parents
of the linked cells.

When a cell is not a linked one, I am geting a COMException. Therefore
I use a try-catch block. But this block reduces the speed of the
program dramatically.

I need to process 100x10000 cells, and without this block (just do not
do anything for linked cells) it is almost 2.5x faster.

For linked cells, I do not have any heavy work, I just add column
numbers to a list.

Could you suggest a better way to access the parent cells or avoid the
COMException?

Thanks.
ortega
The code looks like the this:

...
Microsoft.Office.Interop.Excel.Range cellRange =
worksheet.get_Range(x, y);
int parentCellColumn = -1;
try
{
if (srcCellRange.Precedents.Count 0)
{
// Max parent count is 1 in the table.
parentCellColumn = srcCellRange.Precedents.Column;
}
}
catch (System.Runtime.InteropServices.COMException e)
{
}
finally
{
...
}
...

Jul 2 '07 #1
2 2435
ortega23

try to check whether srcCellRange.Precedents == null before calling its
Columns property

"ortega23" wrote:
Hi,

I am trying to obtain the column number of the parent of a cell, if
the cell is a linked cell (i.e. its value depends on another cells
value).

I try to read "Precedents"(parent cells) of a "Range"(selection of a
single cell in this case) for each cell in my table to access parents
of the linked cells.

When a cell is not a linked one, I am geting a COMException. Therefore
I use a try-catch block. But this block reduces the speed of the
program dramatically.

I need to process 100x10000 cells, and without this block (just do not
do anything for linked cells) it is almost 2.5x faster.

For linked cells, I do not have any heavy work, I just add column
numbers to a list.

Could you suggest a better way to access the parent cells or avoid the
COMException?

Thanks.
ortega
The code looks like the this:

...
Microsoft.Office.Interop.Excel.Range cellRange =
worksheet.get_Range(x, y);
int parentCellColumn = -1;
try
{
if (srcCellRange.Precedents.Count 0)
{
// Max parent count is 1 in the table.
parentCellColumn = srcCellRange.Precedents.Column;
}
}
catch (System.Runtime.InteropServices.COMException e)
{
}
finally
{
...
}
...

Jul 3 '07 #2
Hi Sergey,

That was the first thing that I tried. But it does not work.
When I have a look at the cellRange in QuickWatch, some of the
properties throw ComExceptions while some others are available.
So I can't even make a null-check without COMException.

Name Value Type
------ ------ ------
Precedents 'cellRange.Precedents' threw an exception of type
'System.Runtime.InteropServices.COMException'
Microsoft.Office.Interop.Excel.Range
{System.Runtime.InteropServices.COMException}
Previous {System.__ComObject}
Microsoft.Office.Interop.Excel.Range {System.__ComObject}
Row 10 int

I am trying to figure out how to make this null check without
exception.
Do you have any suggestions?

Thanks.
ortega

Jul 3 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David Krmpotic | last post by:
hi!! I use the following code to operate excel document: Excel.Application excelApp = new Excel.ApplicationClass(); //excelApp.Visible = true; string workbookPath = "c:\\eltina.xls";...
2
by: Job Lot | last post by:
How can I retrieve value from cells in excel spreadsheet using vb.net thanks
0
by: DMolter | last post by:
I'm trying to define a math problem in excel, so for example a 4 cell block where A1 contians nothing, B1 contains the number 2, A2 contains the '+' sign and B2 contains the number 3, forming a...
4
by: IMS.Rushikesh | last post by:
Hi All, I am trying to execute below code but it gives me an COMException ///// Code Start //// public string GetName(Excel.Range range) { try { if (range.Name != null)
1
by: Mark | last post by:
Hello - I'm opening/saving an Excel workbook from ASP.Net. When I try to save the workbook I get the error: System.Runtime.InteropServices.COMException: The remote procedure call failed. ...
7
by: Alain \Mbuna\ | last post by:
Hi everybody. In my program I have some data that is calculated after some input from the user. I have written some code that opens an Excel workbook, with 5 worksheets and the calculated data...
2
by: Jim S | last post by:
To my surprise and chagrin, newer versions of Access have disabled the functionality that lets users change the data in linked tables that point to a range in an Excel workbook. This is "because of...
5
by: mrid via DotNetMonster.com | last post by:
hi. im exporting data from a vb form to excel. i am able to create a new excel file, save and edit it without any trouble, but the formatting is giving me hell! i need to be able to show certain...
0
by: Grip | last post by:
Hi, I have gone throught the group and Microsoft's online help and have seen many suggestions but I am still seeking clarity: 1. I have an excel spreadsheet. Column A contains text that may...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.