Luigiportucale
New Member
- Joined
- Apr 12, 2024
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
Hi. I am trying to do a Code in excel VBA to refresh SAS tables instead of pivot tables.
I have some tables that contain data and are connected to Statistical Analysis System (SAS) and I need to refresh them.
I am using this code to refresh everything once but sometimes it doesn’t work:
Sub Refresh_All_SAS()
Dim sas As SASExcelAddIn
Dim pt As PivotTable
Dim ws As Worksheet
Dim slcr As SlicerCache
Dim dblEndTime As Double
' Refresh SAS content
Set sas = Application.COMAddIns.Item("SAS.ExcelAddIn").Object
sas.Refresh ThisWorkbook
' Add a pause otherwise the update of the pivots doesn't work
dblEndTime = Timer + 1
Do While Timer < dblEndTime
DoEvents
Loop
'Refresh all pivots
For Each PivotCache In ActiveWorkbook.PivotCaches
PivotCache.Refresh
Next
' Remove selections
For Each slcr In ActiveWorkbook.SlicerCaches
slcr.ClearManualFilter
Next slcr
End Sub
So, this is to refresh all at once but sometimes does not work. If someone could help me with an easier code like just refreshing one SAS table, I would much appreciate it.
Thank you.
I have some tables that contain data and are connected to Statistical Analysis System (SAS) and I need to refresh them.
I am using this code to refresh everything once but sometimes it doesn’t work:
Sub Refresh_All_SAS()
Dim sas As SASExcelAddIn
Dim pt As PivotTable
Dim ws As Worksheet
Dim slcr As SlicerCache
Dim dblEndTime As Double
' Refresh SAS content
Set sas = Application.COMAddIns.Item("SAS.ExcelAddIn").Object
sas.Refresh ThisWorkbook
' Add a pause otherwise the update of the pivots doesn't work
dblEndTime = Timer + 1
Do While Timer < dblEndTime
DoEvents
Loop
'Refresh all pivots
For Each PivotCache In ActiveWorkbook.PivotCaches
PivotCache.Refresh
Next
' Remove selections
For Each slcr In ActiveWorkbook.SlicerCaches
slcr.ClearManualFilter
Next slcr
End Sub
So, this is to refresh all at once but sometimes does not work. If someone could help me with an easier code like just refreshing one SAS table, I would much appreciate it.
Thank you.