Can outlook open excel when i get an email using vba

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
I was woundering if this is possible

I have outlook open most of the time,
I have a macro in excel that works perfectly call "New_Sales"

I noiced that Outlook has a VBA section, so
is it possible to get a macro that I can put in Outlook that
When I get an Email from "Accounts@myemailaddress.com"
it triggers the vba to open the excel document
My Documents/Accounts "New Sales Records" and runs macro
"New_Sales"

thanks

Tony
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try This:

VBA Code:
Private Sub Application_NewMail()
    Dim objMail As Outlook.MailItem
    Set objMail = Application.ActiveExplorer.Selection.Item(1)
    
    If objMail.SenderEmailAddress = "accounts@myemailaddress.com" Then
        Dim xlApp As Excel.Application
        Set xlApp = CreateObject("Excel.Application")
        xlApp.Visible = True
        xlApp.Workbooks.Open "C:\Users\Username\Documents\Accounts\New Sales Records.xlsx"
        xlApp.Run "New_Sales"
    End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top