Script in rule not working properly after reboot RRS feed

  • Question

  • Hello,

    I have made a rule in Outlook 2013 to move e-mails with certain words in the topic to a folder, and then run a script on them that looks for pdf affachments with certain codes in the filename, and then copies these to a folder on the HD depending on the code.

    The problem is that when I switch off my computer and restart it the next day, the script doesn't seem to function properly anymore on mails that come in when I start outlook. It will move the e-mails to the subfolder correctly, but it will not copy the attachments to the HD. It also somehow marks all e-mails as read, even ones that it shouldn't according to the script (I want to keep mails with pdf attachments that do not have one of the codes in the file name unread). Interestingly, when I send a test mail to myself after that with a pdf attachment, it does seem to work properly. In the trust center settings I have enabled all macros, so this cannot be the issue.

    Public Sub saveAttachment(itm As Outlook.MailItem)
    Dim objAtt As Outlook.Attachment
    Dim saveFolder As String
    saveFolder = "\\Folder"
    Dim test As Long
    test = 0
         For Each objAtt In itm.Attachments
              If InStr(objAtt.DisplayName, ".pdf") Then
              If InStr(objAtt.DisplayName, "Code1") Then
                  objAtt.SaveAsFile saveFolder & "\Subfolder1\" & objAtt.DisplayName
              ElseIf InStr(objAtt.DisplayName, "Code2") Then
                  objAtt.SaveAsFile saveFolder & "\Subfolder2\" & objAtt.DisplayName
              ElseIf InStr(objAtt.DisplayName, "Code3") Then
                  objAtt.SaveAsFile saveFolder & "\Subfolder3\" & objAtt.DisplayName
                  objAtt.SaveAsFile saveFolder & "\TEMP\" & objAtt.DisplayName
                  test = test + 1
              End If
              End If
              Set objAtt = Nothing
                If test = 0 Then
                itm.UnRead = False
                End If
    End Sub

    If anyone has an idea about what might be the problem and how to solve it, I would be very happy to hear it.



    • Edited by SteRom Tuesday, December 9, 2014 9:37 AM
    Tuesday, December 9, 2014 9:33 AM

All replies

  • Does it work if you make SaveFolder a folder on your local drive? It could be that the connection to the network address is not available.

    Graham Mayor - Word MVP

    Tuesday, December 9, 2014 10:31 AM
  • Thank you for your suggestion!

    I attempted this, but the results are unfortunately the same, so I don't think the network connetion is the problem. When I start my computer and Outlook, the incoming e-mails containing the keyword are moved to the designated folder in my inbox, all marked as read (even the ones that shouldn't be), and no attachment is copied to the HD. When I then go on to send an e-mail to myself with one of the keywords in the subject and a pdf attachment, it is processed correctly. It therefore seems that the script itself is also not what is causing the problem...

    Update: I thought the script might somehow not be working because these were all e-mails that came in the moment I started outlook, but the script also does not work properly on emails coming in while outlook is running (except, strangely, when I'm sending e-mails to myself from the receiving e-mail address or from one of my alternative e-mail addresses...)

    • Edited by SteRom Thursday, December 11, 2014 10:56 AM
    Thursday, December 11, 2014 9:13 AM