title: Outlook 2010: Macro: Add attachments with dynamic file name
body: <p><strong>Program:</strong>  Outlook 2010<br>
  <strong>OS:</strong>  Win8<br>
  <strong>VBA Skill:</strong> Novice</p>
  
  <p><strong>Requirement</strong><br>
  I have a template.oft for sales reports which I call through this Macro.<br>
  The macro attaches a file with a static &amp; secondly, a dynamic name.<br>
  I want to attach the dynamic file using another variable of some sort.</p>
  
  <pre><code>'Working File
      Sub zzzAccs()
          Dim newItem As Outlook.mailItem
          Dim dateFormat As String
              dateFormat = Format(Now, "YYYYMMDD")
  
          Set newItem = CreateItemFromTemplate(":\location\zzz accs.oft")
  
              newItem.Attachments.Add ":\location\" &amp; "zzz sales_" &amp; Format(Now, "YYYYMMDD") &amp; ".pdf"
  
          'Attachment 2 - always will have the same name, general notice/reminder
              newItem.Attachments.Add ":\location\zzz Notice.pdf"
  
              newItem.Display
      End Sub
  </code></pre>
  
  <p><strong>What I want</strong>
  To call a file with a wildcard.  </p>
  
  <p>It will always have:<br>
      <em>":\location\zzz Acc (wildcard, namely date within the last month).pdf"</em>  </p>
  
  <p>This way it will always pick the Account file, but the date or dynamic wildcard will either be dated in the current month, or something different.</p>
  
  <p>eg:
  ":\location\zzz Acc 20140201.pdf"   (current month, but not a defined 'date from now')
  ":\location\zzz Acc statement Feb 2014.pdf"  (will change based on what the file is for).  </p>
  
  <p><strong>Note</strong><br>
  I have since tried the following, however it will only attach 1 file, not all files with wildcards:  </p>
  
  <pre><code>'source:    http://stackoverflow.com/a/13729215/2337102
      Dim strPath As String
      Dim strFilter As String
      Dim strFile As String
  
      strPath = "E:\My Documents\"      'Edit to your path
      strName = "test_"  'added in file core name as I didn't want all the .pdf attached
      strFilter = "*.pdf"
      strFile = Dir(strPath &amp; strName &amp; strFilter)
  
  'New email message from Template
      Set newItem = CreateItemFromTemplate("E:location\test.oft")
  
  'File Locations
      newItem.Attachments.Add "E:\My Documents\" &amp; "test - " &amp; Format(Now, "YYYYMMDD") &amp; ".pdf"
      newItem.Attachments.Add "E:\My Documents\test.pdf"  
  
      newItem.Attachments.Add (strPath &amp; strFile)
      'the above line only attached 1 file, not 3 that were named according to the str Rules eg:  
      'test_2014; test_20140131; test_agreement
  </code></pre>
  
  <p>Please advise.</p>