PC Review


Reply
Thread Tools Rate Thread

C# Excel Named Range Cannot be Found Due to Web Service Data Delay

 
 
FrankJO
Guest
Posts: n/a
 
      13th Nov 2008
Hello,

I am having difficulty waiting on a named range to be created in Excel. The
range is created from returned web service data. The web service returns data
into a matrix, the matrix is then set to an Excel range, and the range is
named "HFReturnRange".

The "activeCell.FormulaR1C1 = formula" is what starts the web service data
retrieval. The returned data then populates into a range underneath this
formula.

The problem is it takes a couple seconds for the web service data to be
returned and populated, and the subsequent code needs to reference the range
and the range.Name created by this data. So, due to the delay, I am in
essentially trying to reference a range name that does not yet exist.

I put together the loops below in an attempt to cycle until the range.Name
exists. I setup a foreach loop to iterate through the named ranges in the
worksheet BSGDataDump, and break out if it finds "HFReturnRange". I then
placed a goto statement to have it repeat the foreach loop until the named
range exists. I am missing something fundamental, however, because the loop
never ends, even after more than enough time has past for the web service
data to populate.

I appreciate any suggestions! I also tried to use the
System.Threading.Thread.Sleep() approach, but this just delayed everything,
and the result was the same.

Code:

activeCell.FormulaR1C1 = formula;

bool DoesHFReturnRangeExist = false;

Repeat:
foreach (Name rangeName in BSGDataDump.Names)
{
if ((String)rangeName.Name == "HFReturnRange")
{
DoesHFReturnRangeExist = true;
BSGDataDump.get_Range("A10",
System.Type.Missing).Value2 = "Range exists.";
break;
}
}

if (DoesHFReturnRangeExist == false)
{
goto Repeat;
}
else
{
goto Proceed;
}

Proceed:
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to print a named range of data excel Rachel Microsoft Excel Programming 1 18th Feb 2009 10:11 AM
Named Range DTS Import of Excel Data =?Utf-8?B?SGFyb2xkIEk=?= Microsoft Excel Misc 0 28th Sep 2007 05:38 PM
Re: Excel Named Range Not Found John Nurick Microsoft Access External Data 0 20th Aug 2004 07:41 AM
sending data to excel to a named range Scott Microsoft Excel Discussion 2 28th Nov 2003 11:37 PM
sending data to a named range in excel Scott Microsoft Access External Data 3 28th Nov 2003 08:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:36 AM.