Update all pivot tables in a workbook
Sub RefreshAllPivots()
Dim ws As Worksheet
Dim pt As PivotTable
On Error Resume Next
For Each ws In ActiveWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.RefreshTable
Next
Next
End Sub
Sub RefreshAllPivots()
Dim ws As Worksheet
Dim pt As PivotTable
On Error Resume Next
For Each ws In ActiveWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.RefreshTable
Next
Next
End Sub
Here is an Outlook macro that saves email attachments to the C:\ folder. It uses a For Loop nested in an If statement, as well as a Select Case statement.
On Error Resume Next
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
Set MyItem = ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set MyItem = ActiveInspector.CurrentItem
Case Else
End Select
On Error GoTo 0
If MyItem Is Nothing Then
Exit Sub
End If
Set myAttachments = MyItem.Attachments
If myAttachments.Count> 0 Then
For i = 1 To myAttachments.Count
Att = myAttachments.Item(i).DisplayName
myAttachments.Item(i).SaveAsFile "C:\" & Att
Next i
End If
Set myAttachments = Nothing
Set MyItem = Nothing
End Sub
Source: http://www.codeforexcelandoutlook.com/blog/