Setup outlook settings from excel vba

bensonsearch

Well-known Member
Joined
May 26, 2011
Messages
844
Hi all,

I need to make changes to about 20 PC's in outlook (add a rule and add macro in outlook). I can do this one by one but would be ALOT easier to put it in excel macro and get staff to open macro and done all at once.

The rule would be with specific subject words (eg "YO SUPERMAN") and then call macro and delete email that came in.

any and all help would be great otherwise im stuck doing it one at a time. :(
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Can't you ask your system Admin people to set this rule to the pc's?
 
Upvote 0
Look at this sample code then it came from this website

http://www.msofficegurus.com/category/Microsoft-Outlook-VBA.aspx

Also look here

http://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/8ac141a2-c0ac-4f35-b226-b4aca8232669/

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> createOutlookRule()<br><SPAN style="color:#00007F">Dim</SPAN> appOutlook <SPAN style="color:#00007F">As</SPAN> Outlook.Application<br><SPAN style="color:#00007F">Dim</SPAN> olRules <SPAN style="color:#00007F">As</SPAN> Outlook.Rules<br><SPAN style="color:#00007F">Dim</SPAN> myRule <SPAN style="color:#00007F">As</SPAN> Outlook.Rule<br><SPAN style="color:#00007F">Dim</SPAN> moveToAction <SPAN style="color:#00007F">As</SPAN> Outlook.MoveOrCopyRuleAction<br><SPAN style="color:#00007F">Dim</SPAN> fromAction <SPAN style="color:#00007F">As</SPAN> Outlook.ToOrFromRuleCondition<br><SPAN style="color:#00007F">Dim</SPAN> myInbox <SPAN style="color:#00007F">As</SPAN> Outlook.Folder<br><SPAN style="color:#00007F">Dim</SPAN> moveToFolder <SPAN style="color:#00007F">As</SPAN> Outlook.Folder<br><br><SPAN style="color:#00007F">Set</SPAN> appOutlook = <SPAN style="color:#00007F">New</SPAN> Outlook.Application<br><SPAN style="color:#00007F">Set</SPAN> myInbox = appOutlook.Session.GetDefaultFolder(olFolderInbox)<br><SPAN style="color:#00007F">Set</SPAN> moveToFolder = myInbox.Folders("MyWorkFlow")<br><SPAN style="color:#00007F">Set</SPAN> olRules = appOutlook.Session.DefaultStore.GetRules()<br><SPAN style="color:#00007F">Set</SPAN> myRule = olRules.Create("My Test Rule", olRuleReceive)<br><SPAN style="color:#00007F">Set</SPAN> fromAction = myRule.Conditions.From<br><br><SPAN style="color:#007F00">' With the "from" action</SPAN><br><SPAN style="color:#00007F">With</SPAN> fromAction<br><SPAN style="color:#007F00">' Enable the condition</SPAN><br><br>.Enabled = <SPAN style="color:#00007F">True</SPAN><br><br><SPAN style="color:#007F00">' Add the e-mail sender</SPAN><br><SPAN style="color:#007F00">' Here, I use the user-friendly name in my address book</SPAN><br>.Recipients.Add ("Robert Martim")<br><br><SPAN style="color:#007F00">' Resolve the recipients so that we know they're valid</SPAN><br>.Recipients.ResolveAll<br><SPAN style="color:#00007F">End</SPAN> With<br><br><SPAN style="color:#007F00">' Determine the action type (moveToFolder, in this case)</SPAN><br><SPAN style="color:#00007F">Set</SPAN> moveToAction = myRule.Actions.moveToFolder<br><br><SPAN style="color:#007F00">' <SPAN style="color:#00007F">With</SPAN> the moveToAction</SPAN><br>With moveToAction<br><SPAN style="color:#007F00">' Enable the action</SPAN><br>.Enabled = <SPAN style="color:#00007F">True</SPAN><br><br><SPAN style="color:#007F00">' Determines the destination folder</SPAN><br>.Folder = moveToFolder<br><SPAN style="color:#00007F">End</SPAN> With<br><br><SPAN style="color:#007F00">' Save the rule in Outlook's Rules list</SPAN><br>olRules.Save<br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,258
Members
452,901
Latest member
LisaGo

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