472,952 Members | 2,484 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,952 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 2420
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: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.