Hello All,
Some background:
I've been using a perl script(not that it matters much since it's just calling the same DLLs
) for a number of years to auto-magically refresh QueryTables in Excel workbooks via Task Scheduler.
Moving to Office 2013 this stopped working. (the script FYI: link )
It not being my code and interested in a solution that wasn't a blackbox I started digging into it and thought I'd recreate it in C#.
Most of the "how do you refresh connections in excel" questions talk about QueryTable.Refresh...
But after that not working I wrote the below debug code and the output tells me that there aren't actually any QueryTables in the Excel file.
Then I stumbled onto this: Microsoft.Office.Interop.Excel.WorkbookConnection ( link ) link2
So I guess my question is, what did I do that the connections aren't seen as QueryTables anymore and how to do I fix them? (They do look like QueryTables...ie, It's an external connection that feeds to a Table)
Also, more generally , is there something fundamental that I'm missing?
Many Thanks and sorry for the overly long background/question.
Regards,
Alex
Excel.Sheets oSheets = (Excel.Sheets)theWorkbook.Worksheets;
theWorkbook.
foreach (Excel.Worksheet oWorkSheet in oSheets)
{
Console.WriteLine(oWorkSheet.Name);
foreach (Excel.QueryTable qt in oWorkSheet.QueryTables)
{
Console.WriteLine(" qt");
etc etc etc...this foreach loop is never entered..
This works though
foreach (Microsoft.Office.Interop.Excel.WorkbookConnection i in theWorkbook.Connections)
{
System.Console.WriteLine(i.Name);
i.OLEDBConnection.BackgroundQuery = false;
i.Refresh();
Bookmarks