title: Set excel slicer to todays date
body: <p>I have a date slicer connected to a pivottable and two pivotcharts. I want this slicer to automatically filter to todays date. I recon I have to do this using VBA code, so I googled and found the following code, from this answer:
  <a href="https://social.msdn.microsoft.com/Forums/office/en-US/2542f1dc-ca62-4ea4-b686-bfa78b53c699/automatically-select-last-available-date-slicer-value-when-opening-workbook?forum=exceldev" rel="nofollow">https://social.msdn.microsoft.com/Forums/office/en-US/2542f1dc-ca62-4ea4-b686-bfa78b53c699/automatically-select-last-available-date-slicer-value-when-opening-workbook?forum=exceldev</a></p>
  
  <pre><code>Private Sub Workbook_Open()
      Dim today As Date
      today = Now
      Dim todayString As String
      todayString = Format$(today, "d mmm yyyy")
  
      Dim item As SlicerItem
  
      For Each item In ThisWorkbook.SlicerCaches("Date Slicer").SlicerItems
          If item.Name = todayString Then
              item.Selected = True
          Else
              item.Selected = False
          End If
      Next item
  
      ThisWorkbook.RefreshAll
  
  End Sub
  </code></pre>
  
  <p>However, when I applied this code, I got the following error: </p>
  
  <pre><code>Run-time error '2004':
  Application-defined or object-defined error
  </code></pre>
  
  <p>Does anyone got working code to manipulate the date slicer, or know why this doesn't work?</p>