title: How to save an xml attachment using element name as file name in VBA
body: <p>I currently have two modules which work as required in VBA created from bits and pieces I found using Google.  </p>
  
  <p>I would like to combine them into one process that Outlook can handle as a rule.  </p>
  
  <p>The first module saves an XML email attachment with a date extension from outlook and is activated by outlook rules.  </p>
  
  <p>The second uses <code>getElementsByTagName</code> to display the serial number from a file located on my hard drive in a msgbox.  </p>
  
  <p>Is there a way to combine these two into one automated process which saves the XML attachment from the email and renames it with the serial number element tag name from the xml attachment?  </p>
  
  <p>The code for each is listed below.  </p>
  
  <p>Module 1:</p>
  
  <pre><code>Public Sub saveXMLtoDisk(itm As Outlook.MailItem)
  Dim objAtt As Outlook.Attachment
  Dim dateFormat
  Dim saveFolder As String
  saveFolder = "C:\temp\xml folder\"
  dateFormat = Format(Now, "mm-dd-yyyy H-mm-ss")
  
   For Each objAtt In itm.Attachments
      If InStr(objAtt.DisplayName, ".xml") Then
       objAtt.SaveAsFile saveFolder &amp; "\" &amp; objAtt.DisplayName &amp; dateFormat &amp; ".xml"
  
        End If
        Set objAtt = Nothing
        Pause 1
        Next
  End Sub
  </code></pre>
  
  <p>Module 2:</p>
  
  <pre><code>Sub GetSN()
  
  Set xmlDoc = CreateObject("Microsoft.XMLDOM")
  xmlDoc.SetProperty "SelectionLanguage", "XPath"
  xmlDoc.async = False
  xmlDoc.Load ("C:\Temp\savetest.xml")
  
  Set nodeXML = xmlDoc.getElementsByTagName("SerialNumber")
  For i = 0 To nodeXML.Length - 1
  MsgBox nodeXML(i).Text
  
  Next
  End Sub
  </code></pre>