First of all I think the Period field must be under the Rows section of the PivotTable Fields pane (alone or among other fields - order doesn't matter):

Then you would need to replace this:
temp = Sheets("Input").Range("H2")
Sheets("Details").PivotTables("PivotTable1").PivotFields("Period").PivotFilters.Add Type:=xlCaptionEquals, Value1:=temp
with this:
With Sheets("Details").PivotTables("PivotTable1").PivotFields("Period")
.ClearAllFilters
.PivotFilters.Add Type:=xlSpecificDate, Value1:=Sheets("Input").Range("H2").Value2
End With
You might want to do some checks before running your code because sheet names can change as well as pivot table names and so on. Also instead of Sheets maybe use ThisWorkbook.Worksheets. This way you are not reffering to the ActiveWorkbook but to the Workbook where the code is running.
EDIT
Here's code that does some checks like mentioned above:
Option Explicit
Sub RefreshPivots()
Dim pivTable1 As PivotTable
Dim pivTable2 As PivotTable
Set pivTable1 = GetPivotTable(ThisWorkbook, "Details", "PivotTable1")
If pivTable1 Is Nothing Then
'Do Something. Maybe Exit or display a MsgBox
End If
pivTable1.PivotCache.Refresh
Set pivTable2 = GetPivotTable(ThisWorkbook, "Details", "PivotTable2")
If pivTable2 Is Nothing Then
'Do Something. Maybe Exit or display a MsgBox
End If
pivTable2.PivotCache.Refresh
Dim periodField As PivotField
On Error Resume Next
Set periodField = pivTable1.PivotFields("Period")
On Error GoTo 0
If periodField Is Nothing Then
'Do Something. Maybe Exit or display a MsgBox
End If
On Error GoTo 0
Dim filterDate As Variant
On Error Resume Next
filterDate = ThisWorkbook.Worksheets("Inputs").Range("H2").Value2
If Err.Number <> 0 Then
'Do Something. Maybe Exit or display a MsgBox
Else
Select Case VarType(filterDate)
Case vbDouble
'Maybe check if serial number is valid
Case vbString
filterDate = CDbl(CDate(filterDate))
Case Else
'Maybe show a MsgBox
Exit Sub
End Select
End If
On Error GoTo 0
With periodField
.ClearAllFilters
.PivotFilters.Add Type:=xlSpecificDate, Value1:=filterDate
End With
End Sub
Private Function GetPivotTable(ByVal sourceBook As Workbook _
, ByVal wSheetName As String _
, ByVal pivotName As String _
) As PivotTable
On Error Resume Next
Set GetPivotTable = sourceBook.Worksheets(wSheetName).PivotTables(pivotName)
On Error GoTo 0
End Function
EDIT 2
I've simplified the filter date check and added some code instead of the "Maybe" comments:
Sub RefreshPivots()
Dim pivTable1 As PivotTable
Dim pivTable2 As PivotTable
Set pivTable1 = GetPivotTable(ThisWorkbook, "Details", "PivotTable1")
If pivTable1 Is Nothing Then
MsgBox "Missing Pivot Table", vbInformation, "Cancelled"
Exit Sub
End If
pivTable1.PivotCache.Refresh
Set pivTable2 = GetPivotTable(ThisWorkbook, "Details", "PivotTable2")
If pivTable2 Is Nothing Then
MsgBox "Missing Pivot Table", vbInformation, "Cancelled"
Exit Sub
End If
pivTable2.PivotCache.Refresh
Dim periodField As PivotField
On Error Resume Next
Set periodField = pivTable1.PivotFields("Period")
On Error GoTo 0
If periodField Is Nothing Then
MsgBox "Missing Pivot Field", vbInformation, "Cancelled"
Exit Sub
End If
On Error GoTo 0
'Maybe check if date is within a certain range
' If filterDate < minDate Or filterDate > maxDate Then
' MsgBox "Invalid Date", vbInformation, "Cancelled"
' Exit Sub
' End If
Dim filterDate As Variant
On Error Resume Next
filterDate = ThisWorkbook.Worksheets("Inputs").Range("H2").Value2
If VarType(filterDate) = vbString Then filterDate = CDbl(CDate(filterDate))
If Err.Number <> 0 Or VarType(filterDate) <> vbDouble Then
MsgBox "Missing/Invalid Filter Date", vbInformation, "Cancelled"
Err.Clear
Exit Sub
End If
On Error GoTo 0
With periodField
.ClearAllFilters
.PivotFilters.Add Type:=xlSpecificDate, Value1:=filterDate
End With
End Sub
EDIT 3
Based on updated question:
Option Explicit
Sub RefreshPivots()
Dim pivTable1 As PivotTable
Dim pivTable2 As PivotTable
Set pivTable1 = GetPivotTable(ThisWorkbook, "Details", "PivotTable1")
If pivTable1 Is Nothing Then
MsgBox "Missing Pivot Table", vbInformation, "Cancelled"
Exit Sub
End If
pivTable1.PivotCache.Refresh
Set pivTable2 = GetPivotTable(ThisWorkbook, "Details", "PivotTable2")
If pivTable2 Is Nothing Then
MsgBox "Missing Pivot Table", vbInformation, "Cancelled"
Exit Sub
End If
pivTable2.PivotCache.Refresh
Dim periodField As PivotField
On Error Resume Next
Set periodField = pivTable1.PivotFields("Period")
On Error GoTo 0
If periodField Is Nothing Then
MsgBox "Missing Pivot Field", vbInformation, "Cancelled"
Exit Sub
End If
periodField.ClearAllFilters
'Maybe check if date is within a certain range
' If filterDate < minDate Or filterDate > maxDate Then
' MsgBox "Invalid Date", vbInformation, "Cancelled"
' Exit Sub
' End If
Dim filterDate As Variant
On Error Resume Next
filterDate = ThisWorkbook.Worksheets("Inputs").Range("H2").Value2
If Err.Number <> 0 Then
Err.Clear
MsgBox "Missing Filter Date", vbInformation, "Cancelled"
Exit Sub
End If
'Try String first
If VarType(filterDate) = vbString Then
periodField.PivotFilters.Add Type:=xlCaptionEquals, Value1:=filterDate
If Err.Number = 0 Then Exit Sub
filterDate = CDbl(CDate(filterDate))
Err.Clear
End If
If VarType(filterDate) <> vbDouble Then
MsgBox "Invalid Filter Date", vbInformation, "Cancelled"
Exit Sub
End If
'Try Date (as Double data type)
periodField.PivotFilters.Add Type:=xlSpecificDate, Value1:=filterDate
If Err.Number <> 0 Then
Err.Clear
MsgBox "Could not apply filter", vbInformation, "Cancelled"
Exit Sub
End If
End Sub
Private Function GetPivotTable(ByVal sourceBook As Workbook _
, ByVal wSheetName As String _
, ByVal pivotName As String _
) As PivotTable
On Error Resume Next
Set GetPivotTable = sourceBook.Worksheets(wSheetName).PivotTables(pivotName)
On Error GoTo 0
End Function
tempwhen this fails?SEP 03/20which is the date I am trying to change the pivot too.SEP 03/20or a date that has formatting applied to it?xlSpecificDateinstead ofxlCaptionEquals... might be misleading you though, not sure.