title: Extract Email Data such as "From" and "To"
body: <p>I want to go into a specified folder in Outlook and based on a variable (value/named range in Excel) extract data from emails (To, Subject, etc.).</p>
  <p>I can extract only the &quot;Subject&quot; and &quot;Size&quot; data of the emails.</p>
  <p>If I try to pull in the &quot;To&quot; data, for example, it comes up with</p>
  <blockquote>
  <p>&quot;Run-time error '438': Object doesn't support this property or method error.</p>
  </blockquote>
  <pre class="lang-vb prettyprint-override"><code>Sub FetchEmailData()
  
      Dim appOutlook As Object
      Dim olNs As Object
      Dim olFolder As Object
      Dim olItem As Object
      Dim iRow As Integer
       
      'Get/create Outlook Application
      On Error Resume Next
      Set appOutlook = GetObject(, &quot;Outlook.Application&quot;)
      If appOutlook Is Nothing Then
          Set appOutlook = CreateObject(&quot;Outlook.Application&quot;)
      End If
      On Error GoTo 0
       
      Set olNs = appOutlook.GetNamespace(&quot;MAPI&quot;)
      Set olFolder = olNs.Folders(&quot;Mailbox_name&quot;).Folders(&quot;Inbox&quot;).Folders(&quot;XYZ&quot;).Folders(&quot;2017&quot;).Folders(&quot;04. April&quot;).Folders(&quot;Etc&quot;)
  
      'Clear
      ThisWorkbook.Sheets(&quot;Test&quot;).Cells.Delete
  
      'Build headings:
      ThisWorkbook.Sheets(&quot;Test&quot;).Range(&quot;A1:D1&quot;) = Array(&quot;Sender_Email_Address&quot;, &quot;Subject&quot;, &quot;To&quot;, &quot;Size&quot;)
  
      For iRow = 1 To olFolder.Items.Count
          ThisWorkbook.Sheets(&quot;Test&quot;).Cells(iRow, 1).Select
          'ThisWorkbook.Sheets(&quot;Test&quot;).Cells(iRow, 1) = olFolder.Items.Item(iRow).SenderEmailAddress
          ThisWorkbook.Sheets(&quot;Test&quot;).Cells(iRow, 2) = olFolder.Items.Item(iRow).Subject
          'ThisWorkbook.Sheets(&quot;Test&quot;).Cells(iRow, 3) = olFolder.Items.Item(iRow).To
          ThisWorkbook.Sheets(&quot;Test&quot;).Cells(iRow, 4) = olFolder.Items.Item(iRow).Size
      Next iRow
       
  End Sub
  </code></pre>
  <p>How could I extract fields such as &quot;From&quot; and &quot;To&quot;?</p>
  <p>Also, if my <code>Set olFolder</code> value is a named range in Excel that dynamically changes with the date (<code>=Today()</code>) and uses <code>Folder_Location</code> as the named range in Excel, would it be correct to write;</p>
  <pre><code>Set olFolder = ThisWorkbook.Sheets(&quot;Setup&quot;).Range(&quot;Folder_Location&quot;)
  </code></pre>
  <p>Where</p>
  <pre><code>Folder_Location = olNs.Folders(&quot;Mailbox_name&quot;).Folders(&quot;Inbox&quot;).Folders(&quot;XYZ&quot;).Folders(&quot;2017&quot;).Folders(&quot;04. April&quot;).Folders(&quot;Etc&quot;)     
  </code></pre>
  <p>This errors when I attempt to link it to <code>olFolder</code>.</p>