Romulo Avila
07-28-2016, 07:34 AM
Good Morning,
I have the code below in a rule Outlook to run when new mail arrives, but I'm 02 doubts.
- How do I debug this code when Teclo F8 does not run, if you dial F5 opens the MACRO box but does not appear
- Its run to read all the emails that I have in my inbox
Thank you
===>> Code <<===
Public Sub SalvarXML(Email As MailItem)
Dim DiretorioAnexos As String
DiretorioAnexos = "C:\XML\"
Dim MailID As String
Dim Mail As Outlook.MailItem
Dim fso
MailID = Email.EntryID
Set Mail = Application.Session.GetItemFromID(MailID)
For Each Anexo In Mail.Attachments
On Error Resume Next
If Right(Anexo.FileName, 4) = ".xml" Or Right(Anexo.FileName, 4) = ".XML" Then
Anexo.SaveAsFile DiretorioAnexos & Anexo.FileName
Set objParser = CreateObject("Microsoft.XMLDOM")
objParser.Load (DiretorioAnexos + Anexo.FileName)
oldfilename = DiretorioAnexos + Anexo.FileName
Set ElemList = objParser.getElementsByTagName("chNFe")
chNFe = ElemList.Item(0).Text
NewFileName = DiretorioAnexos + chNFe + ".xml"
Set fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFile oldfilename, NewFileName
End If
Next
Set Mail = Nothing
Email.UnRead = False
Email.Delete
End Sub
I have the code below in a rule Outlook to run when new mail arrives, but I'm 02 doubts.
- How do I debug this code when Teclo F8 does not run, if you dial F5 opens the MACRO box but does not appear
- Its run to read all the emails that I have in my inbox
Thank you
===>> Code <<===
Public Sub SalvarXML(Email As MailItem)
Dim DiretorioAnexos As String
DiretorioAnexos = "C:\XML\"
Dim MailID As String
Dim Mail As Outlook.MailItem
Dim fso
MailID = Email.EntryID
Set Mail = Application.Session.GetItemFromID(MailID)
For Each Anexo In Mail.Attachments
On Error Resume Next
If Right(Anexo.FileName, 4) = ".xml" Or Right(Anexo.FileName, 4) = ".XML" Then
Anexo.SaveAsFile DiretorioAnexos & Anexo.FileName
Set objParser = CreateObject("Microsoft.XMLDOM")
objParser.Load (DiretorioAnexos + Anexo.FileName)
oldfilename = DiretorioAnexos + Anexo.FileName
Set ElemList = objParser.getElementsByTagName("chNFe")
chNFe = ElemList.Item(0).Text
NewFileName = DiretorioAnexos + chNFe + ".xml"
Set fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFile oldfilename, NewFileName
End If
Next
Set Mail = Nothing
Email.UnRead = False
Email.Delete
End Sub