title: Insert formatted Excel Pivot Table into Word
body: <p>I made a template in Word where I have placed bookmarks. My idea was to export from Excel directly to this template.</p>
  <p>On a weekly basis I import data from CSV to a constant Excel template. I export data from Excel to a Word document which is a template with selected areas where data is inserted.</p>
  <p>This process works but I am tired of my pivot tables being imported with visible filters (filters in pivot tables are placed above even pivot tables). I delete these lines manually in Word. This in itself is not a huge problem, but I'm sure this can be solved automatically so that the pivot tables are imported without this &quot;filter line&quot;.</p>
  <p>I found code on the web which inserts my pivot table the way I would like it. I am not competent enough to rewrite my code.</p>
  <p>The code below inserts the pivot table:</p>
  <pre><code>Sub PivotTablePaste ()
      Dim SourcePivottable As PivotTable
      Dim DestinationRange As Range
      Dim aCell As Range
      
      Set SourcePivottable = Worksheets (&quot;Sheet1&quot;). PivotTables (1)
      Set DestinationRange = Worksheets (&quot;Sheet1&quot;). Range (&quot;P1&quot;)
      
      'Copy TableRange1
      SourcePivottable.TableRange1.Copy
      With DestinationRange.Offset (_
        SourcePivottable.TableRange1.Row - SourcePivottable.TableRange2.Row, 0)
          .PasteSpecial Paste: = xlPasteValues
          .PasteSpecial Paste: = xlPasteFormats
          .PasteSpecial Paste: = xlPasteColumnWidths
      End With
      
      'Copy everything above TableRange1 cell-by-cell
      For Each aCell In SourcePivottable.TableRange2.Cells
          If Not Intersect (aCell, SourcePivottable.TableRange1) Is Nothing Then Exit For
          aCell.Copy
          With DestinationRange.Offset (_
            aCell.Row - SourcePivottable.TableRange2.Row, _
            aCell.Column - SourcePivottable.TableRange2.Column)
              .PasteSpecial Paste: = xlPasteValues
              .PasteSpecial Paste: = xlPasteFormats
          End With
      Next aCell
      
  End Sub
  </code></pre>
  <p>This code is my own and inserts the parts from Excel to Word perfectly, except for the visible filter line from the Pivot Table.</p>
  <pre><code>Option Explicit
  
  Sub CreateBasicWordReport()
  
  Dim Wdapp As Object
  Dim savename As String
  Dim FileXt As String
  
  Set Wdapp = CreateObject(&quot;Word.Application&quot;)
  
  With Wdapp
  '.Visible = True
  '.Activate
  
  .Documents.Add &quot;C:\Users\Jonas\Desktop\notattest\Ændringsnotat.docx&quot;
  
  Dim ws As Worksheet
  
  Copy to clipboard
  Set ws = Worksheets.Add
  Sheets(&quot;Eksport - Opsummering&quot;).Select
  ActiveSheet.PivotTables(&quot;PivotTable1&quot;).PivotSelect &quot;&quot;, xlDataAndLabel, True
  Selection.Copy
  .Selection.Goto what:=-1, Name:=&quot;Styklistefase1&quot;
  .Selection.Paste
  Set ws = Worksheets.Add
  Sheets(&quot;Eksport - Opsummering&quot;).Select
  ActiveSheet.PivotTables(&quot;PivotTable3&quot;).PivotSelect &quot;&quot;, xlDataAndLabel, True
  Selection.Copy
  .Selection.Goto what:=-1, Name:=&quot;Styklistefase1a&quot;
  .Selection.Paste
  
  savename = Environ(&quot;userProfile&quot;) &amp; &quot;\Desktop\Exceltest\Export-Ændringsnotat &quot; &amp; _
  Format(Now, &quot;yyyy-mm-dd hh-mm-ss&quot;) &amp; &quot;.docx&quot;
  
  .ActiveDocument.SaveAs2 savename
  
  .ActiveDocument.Close
  .Quit
  
  End With
  
  Set Wdapp = Nothing
  </code></pre>