Solved

vba to toggle send/receive in Outlook 2013

Posted on 2013-10-22
4
1,369 Views
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?

rberke

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

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

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

exit_sub:
    Exit Sub
err_routine:
msgBox Error$
Resume exit_sub

Open in new window

0
Comment
Question by:rberke
  • 3
4 Comments
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
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"
0
 
LVL 5

Author Comment

by:rberke
Comment Utility
I avoid sendkeys whenever possible.

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

Bob
0
 
LVL 5

Accepted Solution

by:
rberke earned 0 total points
Comment Utility
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")

rberke

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.
0
 
LVL 5

Author Closing Comment

by:rberke
Comment Utility
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.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Email signatures have numerous marketing benefits. Here are 8 top reasons to turn your email signature into a marketing channel.
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now