Wait for Workbook.RefreshAll() (C#)

前端 未结 4 762
伪装坚强ぢ
伪装坚强ぢ 2021-01-18 15:50

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 <

4条回答
  •  攒了一身酷
    2021-01-18 16:14

    If you go through your Workbook and set the the BackgroundQuery property of all of your QueryTables to false, RefreshAll should finish before moving on.

    foreach (Worksheet worksheet in workbook.Worksheets)
    {
        foreach (QueryTable table in worksheet.QueryTables)
            table.BackgroundQuery = false;
    }
    
    //This will finish executing before moving on
    workbook.RefreshAll();
    

提交回复
热议问题