+ Reply to Thread
Results 1 to 3 of 3

Method to launch an VBA code when a specific email is received

  1. #1
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    405

    Method to launch an VBA code when a specific email is received

    When my Outlook account receives an email with a very specific subject and has an attached workbook, I want to have Outlook open up an Excel workbook that contains VBA code that I have already written that 1) Pulls the attached file into Excel, 2) Processes the data, 3) Generates a .pdf file, 4) Creates an email that and attaches the .pdf 5) Send the email to the user defined in the attachment from the original email.

    Sounds complicated so I have attached a picture of the flow.Automation Flow.png

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Method to launch an VBA code when a specific email is received

    Hi Bobbbo,

    Since you indicate that items 1 thru 5 are complete, I will focus on the Outlook front end only. What you want can be done in several ways including:
    a. Excel Only. This means the Excel file would always be open, and the Excel file would poll Outlook periodically to determine if there are any Emails to be processing.
    b. Outlook front end that gets triggered each time there is a new Email Item. Outlook would open Excel (which could incur some overhead each time Excel is opened).

    Both solutions require similar code in Excel, because when Excel is triggered, Excel identifies which Emails to process. There may be better ways to do this as I am not an Outlook expert.

    Processing is done for Emails that:
    a. Have a Specific Subject
    b. Are Unread
    c. Have one or more Excel attachments

    In the Outlook and Excel Macros there are constants that you have to modify to suit your needs:
    Please Login or Register  to view this content.
    In the Outlook ThisOutlookSession code module:
    NOTE: For convenience, the Outlook code is included in a separate code module in the attached Excel File.
    Please Login or Register  to view this content.

    In the Excel File ThisWorkbook code module:
    Please Login or Register  to view this content.
    In the Excel File Ordinary Code Module ModOutlookFindEmail:
    Please Login or Register  to view this content.
    It is a best practice to declare all variables. If you misspell a variable in your code, VBA will silently assume it is a Variant variable and go on executing with no clue to you that you have a bug. Go to the VBA development window, click Tools, Options, and check "Require Variable Declaration." This will insert the following line at the top of all new modules:
    Please Login or Register  to view this content.
    This option requires all variables to be declared and will give a compiler error for undeclared variables.

    Lewis

  3. #3
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    405

    Re: Method to launch an VBA code when a specific email is received

    Thanks LJMetzger, what a through answer. I believe you have provided what I need to get started. I will contact you if I run into issues. Thanks so much!

+ 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. Run macro when email with certain subject is received
    By 03staylo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-01-2017, 07:31 AM
  2. Launch outlook and Email specific range of cells
    By Jvollmer33 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 09-19-2013, 07:09 PM
  3. Send New Email W/ Body of Received Email, Then Delete Sent Email
    By edneal2 in forum Outlook Formatting & Functions
    Replies: 2
    Last Post: 07-01-2013, 12:45 AM
  4. Launch email and attach open workbook to email?
    By mlefkowitz in forum Excel General
    Replies: 0
    Last Post: 09-11-2012, 02:01 PM
  5. do something when new email is received in outlook
    By denvernuggets15 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-05-2012, 11:34 PM
  6. See last 3 email i received in excel
    By sunny3131986 in forum Excel General
    Replies: 1
    Last Post: 09-22-2010, 08:26 AM
  7. Email sent but not received?
    By PenguinBacon in forum Excel General
    Replies: 2
    Last Post: 09-06-2007, 02:45 PM

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