vba to toggle send/receive in Outlook 2013

Posted on 2013-10-22
Medium Priority
Last Modified: 2013-10-28
In outlook 2010 I could toggle send/receive with this code

Application.ActiveExplorer().CommandBars("Standard").Controls("Send/Re&ceive").Controls("Send/Recei&ve Settings").Controls("&Disable Scheduled Send/Receive").Execute.

So how can I do the same thing with Outlook 2013?


P.S.  here is the full vba that worked in outlook 2010 and earlier.
Sub toggleScheduledSendReceive()
' this only works in Outlook 2010 and earlier

' the Line1 code must run BEFORE the Line2 .execute command
' if Line1 comes after the .execute it will randomly return the control's PREVIOUS value rather than the TOGGLED value.
        ' this because the .execute runs asynchrously.
       '  Vba starts the .execute, then resumes at line2B 
       '  even though the toggle may or may not have finished.

On Error GoTo err_routine

Dim x

Dim OutlookSendReceiveWasPreviouslyDisabled As Boolean
Line1: OutlookSendReceiveWasPreviouslyDisabled = Application.ActiveExplorer().CommandBars("Standard").Controls("Send/Re&ceive").Controls("Send/Recei&ve Settings").Controls("&Disable Scheduled Send/Receive").State

Application.ActiveExplorer().CommandBars("Standard").Controls("Send/Re&ceive").Controls("Send/Recei&ve Settings").Controls("&Disable Scheduled Send/Receive").Execute

If OutlookSendReceiveWasPreviouslyDisabled Then
      MsgBox "Send/Receive schedule has been Enabled."
     msgBox "Send/Receive and Server Import schedules have been Disabled"
End If

    Exit Sub
msgBox Error$
Resume exit_sub

Open in new window

Question by:rberke
  • 3
LVL 76

Expert Comment

by:David Lee
ID: 39593738
Hi, rberke.

Microsoft effectively did away with commandbars in Outlook 2013.  That's why the code you posted doesn't work.  The simplest solution is to use the following SendKeys command to toggle the setting.

    SendKeys "%SGD"

Author Comment

ID: 39594398
I avoid sendkeys whenever possible.

I would far prefer a solution which uses the object model.


Accepted Solution

rberke earned 0 total points
ID: 39595173
I figured it out myself. My solution is in 3A below.

In Outlook 2013, I can now easily execute most ribbon commands from vba.

First, I find the name of the command as follows:

1) right click QAT>Customize the Ribbon > choose commands from > all Commands
2) hover mouse over the desired command and the command name appears.

3A) I then code the vba as follows

    Application.ActiveExplorer.CommandBars.ExecuteMso ("DisableAutoSendReceive")

Please note, the name is slightly misleading, a better name would have been ToggleAutoSendReceive

3B) If an arbitrary command applies to an open message, I would have coded it slightly differently.  For instance:

     Application.ActiveInspector.CommandBars.ExecuteMso ("RemoveAttach")


p.s. The rumor is that commandbars may be eliminated sometime in the future, but Outlook 2013 is not going to be replaced for at least a couple more years.

Author Closing Comment

ID: 39605112
the sendkeys solution provided by the expert might have worked, but I don't like sendkeys.

I came up with my own solution which is much more general.

Featured Post

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Configure external lookups on for external mail flow on Exchange 2013 and Exchange 2016.
Though there are a few manual ways to import PST files to Office 365 , third-party PST to Office 365 import tools are preferred over them due to various reasons.  Consequently, many tools or services are available for the same. Here, we pick the to…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question