I want to loop through a directory (using C#) and Refresh all Excel sheets in there. I use:
Workbook.RefreshAll();
How can I wait for the Workbook.RefreshAll()
statement to finish?
The problem is: I open FileA
, then Workbook.RefreshAll()
and then open FileB
- Refresh for FileA
is terminated. The only solution I found is to call something like
System.Threading.Thread.Sleep(20000);
which I found very unlovely...
Does someone know a better way to wait?
Updated 31.05.2016...
Thanks for your help. I found the following solution:
foreach (MSExcel.WorkbookConnection cnn in wb.Connections)
{
if (cnn.Type.ToString() == "xlConnectionTypeODBC")
{
cnn.ODBCConnection.BackgroundQuery = false;
}
else
{
cnn.OLEDBConnection.BackgroundQuery = false;
}
}
Frank
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With