Consulting

Results 1 to 5 of 5

Thread: Debug Code VBA

  1. #1

    Debug Code VBA

    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

  2. #2
    Why are you obsessed with running the code from a rule? I have already given you code that demonstrates how to process an individual message and how to process a folder. Run the macro from a ribbon or QAT (Quick Access Toolbar) button, and leave the rules to process individual messages as they arrive.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Graham,
    Good morning, I'm wanting is to automate this task to save the attachment so that the message comes, how will I receive many emails like this, take some time to access them and run the macro for each case.

    And in the case of debug, it is at I try to follow the step-by-step macro, so I can try to understand.

    Thanks again for your help

  4. #4
    I gave you the code for that also - which bears little relationship to what you have posted. Your macro script is

    Public Sub SalvarXML(Email As MailItem)

    As I have explained repeatedly, the incoming message is defined in your script as EMail thus
        'MailID = Email.EntryID 'Not required
        'Set Mail = Application.Session.GetItemFromID(MailID) 'Not required
        For Each Anexo In Email.Attachments 'Change
    I have not tested the rest of your code which bears no resemblance to how I told you to process it. I feel I am wasting my time.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    Graham, good day, do not want to take your time, thank you and excuse my insistence, I lay in VBA, I'm starting now in this area.


    I will trying here, thanks a lot .. hugs ..

Posting Permissions

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