none
Why isn't script consistently working? RRS feed

  • Question

  • This script doesn't always run.

    Sub saveAttachtoDisk(itm As Outlook.MailItem)
    Dim objAtt As Outlook.Attachment
    Dim saveFolder As String
    saveFolder = "C:\Users\me\Desktop\Tasks\weeklyTracking\Dailys"
         For Each objAtt In itm.Attachments
              objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
              Set objAtt = Nothing
         Next
    cCommand = "powershell.exe -nologo -command C:\Users\me\Desktop\Tasks\weeklyTracking\track.ps1"
    Set objShell = CreateObject("WScript.Shell")
    objShell.Run cCommand, 0
    End Sub

    I have a rule set up to find particular emails from an email-address w/ attachments to run this script when they come in. It's supposed to download the attachments to that folder. Then run the powershell script. The powershell script checks to make sure it's the only track.ps1 running before doing its process.

    The problem is, this script sometimes doesn't download the attachments until I reset my outlook and run rule now.

    That's counter productive. 

    How do I keep it automated?

    Is there another way to get attachments downloaded when they come in?

    Tuesday, February 24, 2015 8:35 PM

Answers

  • I gave up. It's just not consistent. I wrote the script in Powershell, and going to use task scheduler to automate it since the emails come in at the same time daily.

    Thanks.

    • Marked as answer by Simon Syncs Wednesday, February 25, 2015 2:24 PM
    Wednesday, February 25, 2015 2:24 PM

All replies

  • Hello Simon,

    Did you try to remove the PowerShell script from the VBA code? Does it work without a PS script?

    The fact is that the script can take some time to finish. Try to leave only the OOM calls.

    Tuesday, February 24, 2015 9:26 PM
  • Hi Simon,

    First, please refer to Eugene’s reply to narrow down the issue. If it has the issue in PowerShell, you could open a new thread in PowerShell forum.

    Secondly, you could create an outlook-add in to achieve that.

    # Creating Your First Application-Level Add-in for Outlook

    https://msdn.microsoft.com/en-us/library/cc668191.aspx

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, February 25, 2015 8:46 AM
    Moderator
  • Hey Eugene,

    When it decides to not work, even removing the powershell lines does not work.

    Nothing works at all until I restart my outlook, or I delete:

    \Documents and Settings\me\Application Data\Microsoft\Outlook\VbaProject.OTM

    I need this script to always work. I cannot have to restart every time. The messages come in around 3 back to back. By time I notice the script is not working, they've all come in.

    Wednesday, February 25, 2015 1:29 PM
  • Hey Starain, 

    Thanks for the advice, I'm going to try creating a Application-Level Add-In.

    Wednesday, February 25, 2015 1:38 PM
  • Try to use the Debug.Print method to see what's going on in the code. Thus, you will be able to find a problematic line of code which causes the issue.
    Wednesday, February 25, 2015 1:42 PM
  • I gave up. It's just not consistent. I wrote the script in Powershell, and going to use task scheduler to automate it since the emails come in at the same time daily.

    Thanks.

    • Marked as answer by Simon Syncs Wednesday, February 25, 2015 2:24 PM
    Wednesday, February 25, 2015 2:24 PM