LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default C# Excel Named Range Cannot be Found Due to Web Service Data Delay

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:
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
office 07: auto powerpoint charts using named range data in excel robert2b Charts and Charting in Excel 0 November 28th 07 11:15 PM
Named Range DTS Import of Excel Data Harold I Excel Discussion (Misc queries) 0 September 28th 07 05:38 PM
Append Excel Data from a named Range to an Exceldatabase [email protected] Excel Programming 3 August 16th 07 06:50 PM
Conditional formatting if value in cell is found in a named range Grumpy Grandpa Excel Worksheet Functions 5 April 15th 06 04:30 PM
Outlook wants an Excel named range to import contact data why? GDB026 Excel Discussion (Misc queries) 1 December 16th 05 04:59 PM


All times are GMT +1. The time now is 02:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"