+ Reply to Thread
Results 1 to 7 of 7

Need a 2nd Outlook rule to trigger a 2nd script.

  1. #1
    Registered User
    Join Date
    11-06-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2010
    Posts
    4

    Need a 2nd Outlook rule to trigger a 2nd script.

    Preface: I don't know VBA, just "Alt + F11" and pasting in the code. Please be nice

    I have an Outlook rule that triggers a script which saves the attachment to a folder (works)

    I need to setup a 2nd rule to trigger a 2nd script (same script as 1st, but with a different file name)

    Creating a 2nd module with 2nd script didn't show up as an option during Rule setup. I can't create a 2nd project to reference either. How can I have a 2nd rule run a 2nd script? I want the rule to decide what needs to be done as I don't know VBA enough to have the script decide the needed action.

    Working Rule: If Email is from "Sender-x" & Subject equals "Subject-1" then Run "Script-1"
    Working Script-1:
    Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
    Dim objAtt As Outlook.Attachment
    Dim saveFolder As String
    saveFolder = "https://website.com/folder/"
    For Each objAtt In itm.Attachments
    objAtt.SaveAsFile saveFolder & "\File Name-1.txt"
    Set objAtt = Nothing
    Next
    End Sub

    2nd Rule Needed: If Email is from "Sender-x" & Subject equals "Subject-2" then Run "Script-2"
    Needed Script-2:
    Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
    Dim objAtt As Outlook.Attachment
    Dim saveFolder As String
    saveFolder = "https://website.com/folder/"
    For Each objAtt In itm.Attachments
    objAtt.SaveAsFile saveFolder & "\File Name-2.txt"
    Set objAtt = Nothing
    Next
    End Sub

  2. #2
    Forum Contributor
    Join Date
    08-27-2006
    Posts
    136

    Re: Need a 2nd Outlook rule to trigger a 2nd script.

    Use a different name

    Please Login or Register  to view this content.
    To mark "Solved" go to Thread Tools.

  3. #3
    Registered User
    Join Date
    11-06-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Need a 2nd Outlook rule to trigger a 2nd script.

    Thanks for the reply. Do you mean to create a 2nd module with that name and line in the code or have both of my scripts in one module and just have part-2 reference a different name?

  4. #4
    Registered User
    Join Date
    11-06-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Need a 2nd Outlook rule to trigger a 2nd script.

    I added Part-2 of my script to "Module1" and changed the line you mentioned. Now when I setup Rules, it sees two scripts to choose from.

    Testing it isn't working, but that's because I'm not getting the emails (Grrr)

    Thanks for your help!

  5. #5
    Forum Contributor
    Join Date
    08-27-2006
    Posts
    136

    Re: Need a 2nd Outlook rule to trigger a 2nd script.

    You can test the code, not the rule conditions, like this.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    11-06-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Need a 2nd Outlook rule to trigger a 2nd script.

    I have a rule pointing to the 2nd script, but not working.

    Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
    Dim objAtt As Outlook.Attachment
    Dim saveFolder As String
    saveFolder = "https://website.com/folder/"
    For Each objAtt In itm.Attachments
    objAtt.SaveAsFile saveFolder & "\File Name-1.txt"
    Set objAtt = Nothing
    Next
    Public Sub saveAttachtoDiskDifferentName(itm As Outlook.MailItem)
    Dim objAtt As Outlook.Attachment
    Dim saveFolder As String
    saveFolder = "https://website.com/folder/"
    For Each objAtt In itm.Attachments
    objAtt.SaveAsFile saveFolder & "\File Name-2.txt"
    Set objAtt = Nothing
    Next
    End Sub

    to Test, do I do this?

    Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
    Dim objAtt As Outlook.Attachment
    Dim saveFolder As String
    saveFolder = "https://website.com/folder/"
    For Each objAtt In itm.Attachments
    objAtt.SaveAsFile saveFolder & "\File Name-1.txt"
    Set objAtt = Nothing
    Next
    Public Sub saveAttachtoDiskDifferentName(itm As Outlook.MailItem)
    Dim objAtt As Outlook.Attachment
    Dim saveFolder As String
    saveFolder = "https://website.com/folder/"
    For Each objAtt In itm.Attachments
    objAtt.SaveAsFile saveFolder & "\File Name-2.txt"
    Set objAtt = Nothing
    Next
    Private Sub saveAttachtoDiskDifferentName_Test()
    ' To test
    ' open a message then run this code
    Dim curritem As Object
    Set curritem = ActiveInspector.currentItem
    saveAttachtoDiskDifferentName curritem
    End Sub

  7. #7
    Forum Contributor
    Join Date
    08-27-2006
    Posts
    136

    Re: Need a 2nd Outlook rule to trigger a 2nd script.

    Do not combine the code.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Outlook VBA running a script with a rule.
    By Rchie in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-28-2015, 11:23 AM
  2. Script problem Error in Rule
    By Shakey88 in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 11-25-2013, 10:17 AM
  3. Outlook Forwarding Script Errors Out and Stops Rule
    By dipique in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 11-14-2013, 03:46 PM
  4. Can I trigger a VBA script without pausing Outlook for the duration?
    By baldmosher in forum Outlook Programming / VBA / Macros
    Replies: 5
    Last Post: 08-05-2013, 07:19 AM
  5. [SOLVED] script to enable a rule
    By tiger10012 in forum Outlook Formatting & Functions
    Replies: 2
    Last Post: 02-11-2013, 10:14 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1