Hi there,
I want to have a sheet which lists all the PQ connections, PP Data Models and PivotTables in the workbook and shows
1) when they were last refreshed
2) how long it took to refresh
3) any errors stopping refresh
4) the order they are refreshed when 'RefreshAll'
5) background enable enabled/disabled (*I have turned this off for all already via VBA code)
6) user who refreshed
7) what PQ are linked to which or preferably: Show the source data of each query
8) I also wanted to show either a progress bar or a msgbox when refresh has been completed.
9) Lastly any code to to remove and re-add data source settings to organisational as other users can't refresh the queries?
I found some really great code which gives me some of this but doesn't provide date and time taken which are the main points I wanted.
Reason for this is its taking so long to refresh that I want to see which ones are the issues and whether I really need them anymore.
Trying to clean up the file to make it faster.
Ensure other colleagues can refresh without issues.
Here's the code I have and the output it currently shows:
Output Sample: (Although 'Enable Refresh' column is not accurate as I've disabled this for all).
Here's the code which I thought I could try and adapt to get time and notification but I get an error:
I know this is a huge Christmas want list but I'll be glad of anything from the list I can get or advice on how to achieve a quick refresh for any user.
FYI (I have table buffered my source queries too).
Many thanks
Melissa
I want to have a sheet which lists all the PQ connections, PP Data Models and PivotTables in the workbook and shows
1) when they were last refreshed
2) how long it took to refresh
3) any errors stopping refresh
4) the order they are refreshed when 'RefreshAll'
5) background enable enabled/disabled (*I have turned this off for all already via VBA code)
6) user who refreshed
7) what PQ are linked to which or preferably: Show the source data of each query
8) I also wanted to show either a progress bar or a msgbox when refresh has been completed.
9) Lastly any code to to remove and re-add data source settings to organisational as other users can't refresh the queries?
I found some really great code which gives me some of this but doesn't provide date and time taken which are the main points I wanted.
Reason for this is its taking so long to refresh that I want to see which ones are the issues and whether I really need them anymore.
Trying to clean up the file to make it faster.
Ensure other colleagues can refresh without issues.
Here's the code I have and the output it currently shows:
VBA Code:
Option Explicit
Private Function GetWbSheet(wb As Workbook, sheetName As String) As Worksheet
Set GetWbSheet = Nothing
On Error Resume Next
Set GetWbSheet = wb.Worksheets(sheetName)
On Error Resume Next
End Function
Public Sub List_Workbook_Connections()
Dim wb As Workbook
Dim qcSheet As Worksheet, r As Long, tableStartRow As Long
Dim wbConn As WorkbookConnection
Dim wbcTable As ListObject
'Either operate on this macro workbook
'Set wb = ThisWorkbook
'Or operate on the active workbook
Set wb = ActiveWorkbook
Set qcSheet = GetWbSheet(wb, "Conns")
If qcSheet Is Nothing Then
With wb
Set qcSheet = .Worksheets.Add(After:=.Worksheets(.Worksheets.Count))
qcSheet.Name = "Conns"
End With
End If
qcSheet.Cells.Clear
r = 1
tableStartRow = r
qcSheet.Cells(r, "A").Resize(, 9).Value = Array("Name", "Description", "RefreshDate", "RefreshWithAll", "EnableRefresh", "InModel", "Type", "ODBC/OLEDB", "CommandText")
r = r + 1
For Each wbConn In wb.Connections
qcSheet.Cells(r, "A").Value = wbConn.Name
Select Case wbConn.Type
Case Is = xlConnectionTypeODBC
qcSheet.Cells(r, "B").Value = wbConn.Description
On Error Resume Next
qcSheet.Cells(r, "C").Value = wbConn.ODBCConnection.RefreshDate
On Error GoTo 0
qcSheet.Cells(r, "D").Value = wbConn.RefreshWithRefreshAll
qcSheet.Cells(r, "E").Value = wbConn.ODBCConnection.EnableRefresh
qcSheet.Cells(r, "F").Value = wbConn.InModel
qcSheet.Cells(r, "G").Value = wbConn.Type
qcSheet.Cells(r, "H").Value = "ODBC"
qcSheet.Cells(r, "I").Value = wbConn.ODBCConnection.CommandText
Case Is = xlConnectionTypeOLEDB
qcSheet.Cells(r, "B").Value = wbConn.Description
On Error Resume Next
qcSheet.Cells(r, "C").Value = wbConn.OLEDBConnection.RefreshDate
On Error GoTo 0
qcSheet.Cells(r, "D").Value = wbConn.RefreshWithRefreshAll
qcSheet.Cells(r, "E").Value = wbConn.OLEDBConnection.EnableRefresh
qcSheet.Cells(r, "F").Value = wbConn.InModel
qcSheet.Cells(r, "G").Value = wbConn.Type
qcSheet.Cells(r, "H").Value = "OLEDB"
qcSheet.Cells(r, "I").Value = wbConn.OLEDBConnection.CommandText
'Case Is = xlConnectionTypeMODEL
'qcSheet.Cells(r, "B").Value = wbConn.Description
'On Error Resume Next
'qcSheet.Cells(r, "C").Value = wbConn.ModelConnection.RefreshDate
' On Error GoTo 0
' qcSheet.Cells(r, "D").Value = wbConn.RefreshWithRefreshAll
' qcSheet.Cells(r, "E").Value = wbConn.ModelConnection.EnableRefresh
' qcSheet.Cells(r, "F").Value = wbConn.InModel
' qcSheet.Cells(r, "G").Value = wbConn.Type
' qcSheet.Cells(r, "H").Value = "MODEL"
' qcSheet.Cells(r, "I").Value = wbConn.ModelConnection.CommandText
End Select
r = r + 1
Next
With qcSheet
Set wbcTable = .ListObjects.Add(xlSrcRange, .Cells(tableStartRow, "A").Resize(r - tableStartRow, 10), , xlYes)
wbcTable.Name = "WorkbookConnections_Table"
End With
End Sub
Output Sample: (Although 'Enable Refresh' column is not accurate as I've disabled this for all).
Here's the code which I thought I could try and adapt to get time and notification but I get an error:
Code:
Sub MyProcedure()
'
' Some procedures
'
ActiveWorkbook.RefreshAll
Call NotifyWhenRefreshComplete
End Sub
Private Sub NotifyWhenRefreshComplete()
Const PulseTimer As Currency = TimeValue("00:00:01")
Dim b1 As Boolean, b2 As Boolean
b1 = Sheet29.Range("ListObject1").ListObject.QueryTable.Refreshing
b2 = Sheet29.Range("ListObject2").ListObject.QueryTable.Refreshing
If b1 Or b2 Then
Call Application.OnTime(Now + PulseTimer, "NotifyWhenRefreshComplete")
Else
Call MsgBox("Refresh Complete.", vbOKOnly)
End If
End Sub
I know this is a huge Christmas want list but I'll be glad of anything from the list I can get or advice on how to achieve a quick refresh for any user.
FYI (I have table buffered my source queries too).
Many thanks
Melissa