Consulting

Results 1 to 2 of 2

Thread: Save an .xml attachment as information from a specific xml tag

  1. #1

    Save an .xml attachment as information from a specific xml tag

    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:
    [vba]
    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
    [/vba]

  2. #2
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    What I do is save the attachment to the local temp folder, then do what I need with it.
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •