PDA

View Full Version : Save an .xml attachment as information from a specific xml tag



ferluchini
03-29-2012, 08:20 AM
Hi friends!

I am trying to make a code to save the XML file attachment, but the filename should be an information from a specific tag from XML. The tag is <chNFe>.
I made the code above, but it is working just when I load the XML from HD. Could someone please help me to load the XML from attachement?


Code:

Sub SaveAttachments(myMail As MailItem)
Dim vFrom As String, vSubject As String
Dim vFile As Attachment
Dim xmlDoc As DOMDocument30
Set xmlDoc = New DOMDocument30
vFrom = myMail.ReceivedByName
vSubject = myMail.Subject

If myMail.Attachments.Count > 0 Then
For i = 1 To myMail.Attachments.Count
Set vFile = myMail.Attachments(i)
Dim nomearq As String
nomearq = "C:\Test\arq_xml.xml"
xmlDoc.Load (Trim(nomearq))
Dim id As String
id = xmlDoc.SelectSingleNode("//nfeProc/protNFe/infProt/chNFe").Text

If LCase(vFile.FileName) Like "*.xml" Then
vFile.SaveAsFile "C:\Test\" & id + ".xml"
End If
Next i
End If

Set myMail = Nothing
Set vFile = Nothing
End Sub

JP2112
05-07-2012, 12:25 PM
What I do is save the attachment to the local temp folder, then do what I need with it.