How to run Excel Macro when a specific email arrives in Outlook...

scottleger4

New Member
Joined
Oct 3, 2016
Messages
41
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I'm trying to do something that in my mind is relatively simple, but I'm not sure how to go about it and my googling hasn't helped much, other than it sounds like this needs to originate in Outlook. Each day I get a specific email with a specific subject that a data file has been updated. I'm looking for a way to open a specific excel file once that email hits my inbox. Once I can get the Excel file open, I think I can handle the VBA in Excel from there for the next steps. Something like this in outlook....

Public Sub UpdateDOS

'when email arrives with subject "DOS Pivot Updated"

Workbooks.Open Filename:= _
"C:\My DOS file.xlsm"

End Sub


Thanks in advance!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
UPDATE: After a bit more research I found this bit of code...

Public Sub OpenMyExcelFile()
Dim File$
Dim Xl As Object ' Excel.Application
Dim Wb As Object ' Excel.Workbook
Dim Ws As Object ' Excel.Worksheet
Dim Rn As Object ' Excel.Range

File = "C:\My File.xlsm"

On Error Resume Next
Set Xl = GetObject(, "excel.application")
On Error GoTo 0
If Xl Is Nothing Then Set Xl = New Excel.Application
Set Wb = Xl.Workbooks.Open(File)
Set Ws = Wb.Sheets(1)
Ws.Activate
Set Rn = Ws.Range("a1")
Rn.Activate
Xl.Visible = True
End Sub

...but when I try to create a rule to run this when a specific email hits my inbox, it doesn't appear in the "run a script" list. Stealing from one of my other scripts, I modified the first line to...

Public Sub OpenMyExcelFile(MItem As Outlook.MailItem)

...and now it shows up in the box to select it, but it gets "deactivated" when I try to finish and apply with the error...

"One or more rules cannot be uploaded to Microsoft Exchange and has been deactivated. This could be because some of the parameters are not supported, or there is insufficient space to store all of your rules."

I'm sure its something simple, but my coding skills are pretty weak. Thanks again in advance!
 
Upvote 0
After playing with this for several days I am still unable to get this to work. Any ideas?
 
Upvote 0

Forum statistics

Threads
1,214,655
Messages
6,120,760
Members
448,991
Latest member
Hanakoro

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