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
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