Calling Ribbon Button in Outlook 2016

Status
Not open for further replies.

Wayne Dardis

New Member
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server 2013
I am not a VBA programmer. The following is the main sub of a project that I cobbled together for Outlook 2007 and was pleased to find it worked for Outlook 2010 a few years later. However, we are moving to Outlook 2016 now and I've found that it does not work as intended.

We have displays outside our meeting rooms that show the schedules for those rooms in the form of Outlook calendars. I've set a recurring appointment with a reminder just after midnight every day. The reminder event triggers this code. From what I've seen, I think that trigger part still works because "ReminderObject.Dismiss" seems to dismiss the reminder. (I don't see it pop up at all.) However, the main purpose of the code fails, and that is to switch the calendar view to the current date, "Go To Today."

I think this might have something to do with the "Go To Today" button existing on the Ribbon or Home Tab or Whateveritiscallednow instead of on the old command menu. So, maybe the syntax of "objExpl.CommandBars.FindControl" etc. has to change?

From what I picked up from Download Office 2016 Help Files: Office Fluent User Interface Control Identifiers from Official Microsoft Download Center , outlookexplorercontrols.xlsx , Row 187 ... The ID for "Today" is still "5497."

Anyway here is the sub as originally cobbled together. Maybe just looking at it will make my trouble clear to someone fluent in this language...

--- --- --- ---
Private Sub m_colReminders_ReminderFire(ByVal ReminderObject As Outlook.Reminder)

Dim objOL As Outlook.Application
Dim objExpl As Outlook.Explorer
Dim objCBB As Office.CommandBarButton
Const cbbThisDayID = 5497
On Error Resume Next​

Set objOL = CreateObject("Outlook.Application")
Set objExpl = objOL.ActiveExplorer
If objExpl.CurrentFolder.DefaultItemType = olAppointmentItem Then
Set objCBB = objExpl.CommandBars.FindControl(, cbbThisDayID)
objCBB.Execute​
End If
Set objOL = Nothing
Set objExpl = Nothing
Set objCBB = Nothing
ReminderObject.Dismiss​
End Sub
--- --- --- ---

Thank you in advance for your time and assistance!
 
I don't think the location of the button matters - it uses the command id or name, not the sendkeys (which would be affected by the location).


This is messy but accomplishes the same thing by switching to the inbox and back to the calendar.

Code:
'Private Sub m_colReminders_ReminderFire(ByVal ReminderObject As Outlook.Reminder)
Private Sub Application_Reminder(ByVal Item As Object)

    Dim objPane As Outlook.NavigationPane
    Dim objCalModule As Outlook.CalendarModule
    Dim objMailModule As Outlook.MailModule
    Dim objNavFolder As Outlook.NavigationFolder

Dim objOL As Outlook.Application
Dim objExpl As Outlook.Explorer
Dim objCBB As Office.CommandBarButton
'On Error Resume Next
Set objOL = CreateObject("Outlook.Application")
Set objExpl = objOL.ActiveExplorer
If objExpl.CurrentFolder.DefaultItemType = olAppointmentItem Then
  
Set objPane = objOL.ActiveExplorer.NavigationPane
   Set objMailModule = objPane.Modules.GetNavigationModule(olModuleMail)
    Set objPane.CurrentModule = objMailModule

  Set objCalModule = objPane.Modules.GetNavigationModule(olModuleCalendar)
    Set objPane.CurrentModule = objCalModule

End If
Set objOL = Nothing
Set objExpl = Nothing
Set objCBB = Nothing
'ReminderObject.Dismiss
End Sub
 
Thank you for the thoughtful reply. I won't be able to try it out until tomorrow sometime, but I do want to clarify...

Is still possible to trigger the command with ID, 5497... "Go To Today" in Outlook 2016?
 
I thought CommandBars.FindControl should still work, although it is deprecated and not the recommended method anymore, but it didn't work for me either. If Michael is around, he might know.
 
I guess Michael isn't around.

Anyway, Diane, I have a question for you... I pasted the code you suggested into my editor and then noticed that you put single quote marks at the beginning of 3 lines:

'Private Sub m_colReminders_ReminderFire(ByVal ReminderObject As Outlook.Reminder)
'On Error Resume Next
'ReminderObject.Dismiss

This appears to have the effect of treating those lines as comments and so they are ignored. I'm not sure if the first two matter, but the last one I'm pretty sure is necessary. I do want the reminder to be dismissed at the end of the process.

Did you intend to comment-out these three lines? If so, why not just remove them entirely?

Thank you again so very much!
 
It seems I figured out what to do and it works here's the code for the entire class module:
Code:
Dim WithEvents m_colReminders As Outlook.Reminders
Dim m_intBusyStatus As Integer

Private Sub Class_Terminate()
    Call DeRefReminders
End Sub
Public Sub InitReminders(objApp As Outlook.Application)
    Set m_colReminders = objApp.Reminders
    m_intBusyStaus = 0
End Sub
Public Sub DeRefReminders()
    Set m_colReminders = Nothing
End Sub
Private Sub m_colReminders_ReminderFire(ByVal ReminderObject As Outlook.Reminder)

    Dim objPane As Outlook.NavigationPane
    Dim objCalModule As Outlook.CalendarModule
    Dim objMailModule As Outlook.MailModule
    Dim objNavFolder As Outlook.NavigationFolder

Dim objOL As Outlook.Application
Dim objExpl As Outlook.Explorer
Dim objCBB As Office.CommandBarButton
On Error Resume Next
Set objOL = CreateObject("Outlook.Application")
Set objExpl = objOL.ActiveExplorer
If objExpl.CurrentFolder.DefaultItemType = olAppointmentItem Then
 
Set objPane = objOL.ActiveExplorer.NavigationPane
   Set objMailModule = objPane.Modules.GetNavigationModule(olModuleMail)
    Set objPane.CurrentModule = objMailModule

  Set objCalModule = objPane.Modules.GetNavigationModule(olModuleCalendar)
    Set objPane.CurrentModule = objCalModule

End If
Set objOL = Nothing
Set objExpl = Nothing
Set objCBB = Nothing
ReminderObject.Dismiss
End Sub

Thank you VERY much!
 
Anyway, Diane, I have a question for you... I pasted the code you suggested into my editor and then noticed that you put single quote marks at the beginning of 3 lines:
i needed to comment them out for my test - one was to change the name of the macro, one was so i'm notified of errors and since i wasn't setting the reminderobject, needed to turn that off too. :)
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
J Calling a Public sub-routine from the script editor via VB script Outlook VBA and Custom Forms 4
A Calling one module from another Outlook VBA and Custom Forms 2
S VSTO calling unmanged function Outlook VBA and Custom Forms 3
H Auto-Dialer for calling contact Using Outlook 2
T PR_MESSAGE_CLASS is reset when calling Save() on item Outlook VBA and Custom Forms 4
TomHuckstep Remove Send/Receive All Folders (IMAP/POP) button from Outlook 365 Ribbon Using Outlook 2
L Getting Index from dropdown inserted on ribbon Outlook VBA and Custom Forms 3
kburrows Outlook 365 - Ribbon Customizations Disappear Using Outlook 0
e_a_g_l_e_p_i Trying to customize the ribbon but can't figure this one out Using Outlook 3
Witzker Customized Ribbon lost every now and then Using Outlook 3
M Disable Contact Card Results when using "Search People" in Outlook Ribbon Using Outlook 7
Witzker Customized ribbon and entries disappeared Using Outlook 0
M In Outlook Calendar remove the buttons: 'Today' and '<' (Back a day) and '>' (Forward a day) that are below the Ribbon and above the calendar display. Using Outlook 0
W Ribbon XML customization Using Outlook 4
M Simplified ribbon missing Using Outlook 3
L Outlook Office 365 client: won't remember my setting File, not to collapse ribbon Using Outlook 2
S How to set up button in ribbon for individual Quick Steps Using Outlook 1
A Possible to hide ribbon with custom appointment form? Outlook VBA and Custom Forms 3
I Retention policies on outlook 2016 ribbon Using Outlook 2
V not able to change name in customize Ribbon Outlook VBA and Custom Forms 1
W Adding A Macro To Message Ribbon Outlook VBA and Custom Forms 2
Diane Poremsky Customize the Outlook Toolbar, Ribbon or QAT Using Outlook 0
M No Show Group on ribbon Using Outlook 8
I Ribbon buttons grayed-out in Outlook 2013 Using Outlook 2
B How can I adjust the ribbon width? I want to see all of my Quick Steps. Using Outlook 1
piusg 2013: Place custom view on the ribbon Using Outlook 3
P Outlook 2007 Calendar Ribbon has changed and I can't fix it Using Outlook 10
R Can I create custom subgroups on the ribbon? Using Outlook 5
M missing iCloud tab on ribbon bar Using Outlook 0
G Adding 3rd-Party Add-In to Home Ribbon in Outlook 2010 Using Outlook 1
E Outlook Ribbon Customization and Deployment Using Outlook 1
C Outlook Calendar Ribbon with iCloud Using Outlook 2
S ADD-IN Ribbon Missing Using Outlook 2
S ADD-IN Ribbon Missing Using Outlook 5
S Outlook 2010 Ribbon - Creating Links To Websites or EXE Files Using Outlook 4
M Move 'Reply All' on Ribbon in Outlook 2010 Using Outlook 2
L Email button on ribbon defaulting to exchange when POP is default Using Outlook 7
K call a help file when click on a button xml ribbon Outlook VBA and Custom Forms 1
J Executing Ribbon Command from Code Outlook 2010 Outlook VBA and Custom Forms 3
T Word 2007 add-in ribbon icons greyed out Outlook VBA and Custom Forms 1
K add a designed group into a existing inspector ribbon Outlook VBA and Custom Forms 7
C Create a Ribbon for the OL2010 Explorer Outlook VBA and Custom Forms 1
T Ribbon Control questions Outlook VBA and Custom Forms 7
S What's the appointment ribbon called? Outlook VBA and Custom Forms 1
H Program "Click on Ribbon Button" Using VBA Outlook VBA and Custom Forms 1
M Can I embed ribbon item into form region? Outlook VBA and Custom Forms 2
R Build custom ribbon in Outlook 2007 Outlook VBA and Custom Forms 3
C Ribbon problem Outlook VBA and Custom Forms 3
J Ribbon question Outlook VBA and Custom Forms 6
R Could i do this with ribbon(outlook2007)? Outlook VBA and Custom Forms 1

Similar threads

Back
Top