title: How to export data from ListView to Excel and PDF (VBA)
body: <p>I have data in a ListView and would like to export this data with column headers to a new Excel file and a PDF file.</p>
  
  <p>The LV is defined as follows:</p>
  
  <pre><code>'listview:
      |  #  |  Col1  |  Col2 |  Col3 | ...
      ==================================
      |  1  |  Val1  |  Val2 |  Val3 | ...
  </code></pre>
  
  <p>I started with this code:</p>
  
  <pre><code>Dim objExcel As Excel.Application
  Dim objWb As Excel.Workbook
  Dim objWs As Excel.Worksheet
  Dim objRange As Excel.Range
  Dim i%, j%
  
  On Error GoTo errMsg
  
  Set objExcel = New Excel.Application
  objExcel.Visible = False
  
  Set objWb = objExcel.Workbooks.Add
  Set objWs = objWb.Sheets("Sheet1")
  
  With objWs
          For i = 1 To Me.lvlist.ListItems.Count
             .Cells(i, 1) = Me.lvlist.ListItems(i).Text
  
             For j = 1 To Me.lvlist.ListItems(i).ListSubItems.Count
                 .Cells(i, j + 1) = Me.lvlist.ListItems(i).SubItems(j)
             Next j
          Next i
  End With
  
  objExcel.Visible = True
  objWs = Nothing
  objWb = Nothing
  objExcel = Nothing
  </code></pre>
  
  <p>But I get an error. How can I achieve my intention? Thanks for your help.</p>
  
  <p>EDIT:
  I edited the code above and now I'm getting the <code>error 438: Object doesn't support this property or method</code>. And the columnheaders aren't export to excel.</p>