I have a pretty complicated Excel file that involves Tables > Pivot Tables as well as Tables > Power Query Generated Tables > Pivot Tables. The PowerQuery was necessary because there was information in the main table that required Unpivoting.
Most subs are behaving very well. I had to use this bit of code for Refreshing, I think because of the Power Query middle man:
Dim lCnt As Long
With ActiveWorkbook
'Turn off Background Refresh of PowerQuery Connections
For lCnt = 1 To .Connections.Count
'Excludes PowerPivot and Other Connections
If .Connections(lCnt).Type = xlConnectionTypeOLEDB Then
.Connections(lCnt).OLEDBConnection.BackgroundQuery = False
End If
Next lCnt
'Refresh
.RefreshAll
'Turn on Background Refresh of PowerQuery Connections
For lCnt = 1 To .Connections.Count
If .Connections(lCnt).Type = xlConnectionTypeOLEDB Then
.Connections(lCnt).OLEDBConnection.BackgroundQuery = False
End If
Next lCnt
End With
Unfortunately, there's one sub that includes both "ActiveWorkbook.RefreshAll" and "ActiveSheet.Copy." I get either "Run-time error '-2147417848 (80010108)'" or Error 1004 when it reaches "ActiveSheet.Copy".
The sub is working with a Sheet that contains 3 Pivot Tables generated from a regular Table. I suspect that the PowerQuery generated tables are somehow causing this issue because an older version of the file with no PowerQuery generated tables worked just fine with these two commands in the same sub.
Does anyone have a possible workaround for either not needing to use PowerQuery to unpivot something, or how maybe another way to Refresh and still be able to use ActiveSheet.Copy?
Many thanks in advance!