Purge an IMAP folder in Outlook 2016 using VBA - vba

In Outlook 2016 I have connected an IMAP folder. Outlook is configured to mark items as deleted in IMAP folders. This is necessary because I want to process those items, that are marked for deletion seperately. After my macro is completed, that IMAP folder should be purged automatically.
In Outlook there is the ribbon "Folder" with the group "purge". In there is the menu "delete" with an menu item to purge the current folder. I can't find a way to execute the function from a VBA macro.
For Outlook 2010 there is this solution:
http://www.vboffice.net/en/developers/purge-deleted-imap-messages/
In Outlook 2016, the findControl method does not find the required control.
Is there any way to purge that folder?
Best solution would be some kind of API function.
Second best would be to simulate a click event on the control of the ribbon. "CommandBars" seems to contain some sort of context menus but not the ribbon controls.
Is it possible to define custom commandbars with standard controls in it? The control id seams to be still "12771".
I very briefly looked into the UI Automation toolkit but have found no good example of how to access the ribbon of a specific application.
Alternatively: can I get access to controls of the quick access toolbar? Adding the correct purge folder control to the quick access toolbar would rely on the user to click on that button at the right moment.

For buttons you can add to a ribbon or the QAT, the idMso can be seen at the end of the text when hovering over the command.
Sub PurgeFolder_Button_idMso()
' For buttons you can add to a ribbon or the QAT,
' the idMso can be seen at the end of the text when hovering over the command.
ActiveExplorer.CommandBars.ExecuteMso ("PurgeFolder")
End Sub

Related

Outlook project distribution with custom tab and button to trigger userform

I have created Userform in Outlook Called "Task Manager", which attach the current emails to the task selected from the list.
As excel has .xlsm and word has .docm to add custom tabs, button and save macro to share it with your colleagues. but I realized that outlook is independant, there is no file related to outlook. So there must be a way to add custom tabs and button to trigger the UI at runtime.
we need to do it other way around? I am looking for a method to share .exe file to another user so that they can install the .fxm files and have a custom tab. already searched internet could not find feasible solution, I don't know the right way to start?

How to manage application options/advanced options?

I need to quickly toggle File > Options > Advanced > Reminders > Play reminder sound setting.
In certain meetings I need to keep Outlook running to get reminders, but don't want the reminder sound.
Currently, I manually toggle the File > Options > Advanced > Reminders > Play reminder sound checkmark.
This needs to be an effective single-click.
I don't want to restart Outlook as there are usually many things open.
I cannot add it to the Quick Access Toolbar.
On the left the option is present in the list of QAT commands, but not in the list of Ribbon commands, otherwise we could access it with ExecuteMso.
Three reasons:
The button is disabled when not in the Calendar window. That's just inelegant.
When I click the button, Outlook crashes and I lose everything that wasn't saved. (Autosave isn't sufficient or functioning. That's a different problem.)
Understanding how to access Outlook settings with VBA opens a whole new world of possibilities.
This Microsoft article series starting at https://learn.microsoft.com/en-us/office/vba/outlook/concepts/getting-started/automating-outlook-from-a-visual-basic-application is about automating Outlook user tasks, like making a calendar appointment. That's not what I want, I want to manage Outlook's options.
There are some discussions about COM add-ins as one method, but that appears beyond me. The effort to learn COM add-ins is out of line with manual effort to achieve the desired goal.
I have some limited Outlook VBA experience but am reasonably comfortable with VBA in Word, Excel.
To disable reminder sound you need to set the below registry key to 0.
Registry key: PlaySound (REG_DWORD) to be set to 0.
Path: HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\options\Reminder
where 16.0 indicates the Outlook version.
Don't forget to restart Outlook to apply changes.
These settings can be overridden on the per appointment basis - you can simply set AppointmentItem.ReminderPlaySound property to false using VBA.
Simulate a button press with ExecuteMso.
https://learn.microsoft.com/en-us/office/vba/api/Office.CommandBars.ExecuteMso
Hover over the button where you would add it to the ribbon/QAT. See text in brackets at the end.
Are the command codes for ExecuteMso documented?
Private Sub ExecuteMso_TextInBrackets()
' https://learn.microsoft.com/en-us/office/vba/api/Office.CommandBars.ExecuteMso
' https://stackoverflow.com/questions/25610998/are-the-command-codes-for-executemso-documented
Dim oAppt As Object
Set oAppt = ActiveInspector.CurrentItem
Debug.Print oAppt.subject
ActiveInspector.CommandBars.ExecuteMso ("TextInBrackets")
End Sub
As with most things in life, the answer is a workaround. In this case, it's AutoHotkey to press the keys for me (ALT F, T, down x 9, ALT P, Enter):
;WIN-O toggles the Outlook alarm sound setting
#o::
SetTitleMatchMode,2 ;inexact match
WinGetActiveTitle, MyWindowTitle
If WinActive(" - email#company.com") ;Poor way to "prove" we're in Outlook
{
;MsgBox, We're in Outlook
Send !ft{Down 9}
Send !p{Enter}
}
Return

VBA when user clicks Send as Attachement

My company has an issue with Outlook when it is triggered to open by Excel that causes Outlook to hang indefinitely when loading (an issue which cannot be easily fixed). We have a few workbooks with custom ribbons where we now check that Outlook is open first before allowing the user to send via email. The problem is that this doesn't account for users that still use the File > Save & Send > Send as Attachment.
I would like to know if anybody knows about a process by which I can add on a routine to the existing button that we could save as an Excel Add In on everyone's Excel that checks first if Outlook is open? I have the Outlook check written so I'm just needing help with finding a way to run it.
Any help is appreciated.
Alternatively you could disable Send as Attachment.
I wouldn't know what is important so I won't copy parts here.
How do you disable “Save and send” in Excel 2010 (in the File ribbon (called backstage in Office 2010)?
Disable the Send button in the Office Menu
You may consider repurposing the ribbon controls. See Temporarily Repurpose Commands on the Office Fluent Ribbon for more information.
Unfortunately the Backstage UI doesn't allow to repurpose controls from the XML markup. You may consider hiding the built-in UI and rebuilding it fully with custom commands. Thus, you will be able to handle the commands on your own. You can read more about that in the Introduction to the Office 2010 Backstage View for Developers article. Also see the Customizing the Office 2010 Backstage View for Developers article.

How to load windows form on custom folder click using outlook add-in

I have added a solution module having a custom folder in MS outlook 2010. I need to open a windows form on folder click event. The form should display in main central region of outlook window (I think it is called an inspector).
How can I achieve this?
You can monitor the Explorer.FolderSwitch event and display your form if the desired folder is current.

Word Add-in - find if dialog has focus?

I am writing a word add-in in VB .NET (using Add-in Express, but I don't think that's relevant).
I have created shortcuts, but I only want them to take effect if the document itself is in focus, not a dialog - for example, "Find and replace" or any other.
How do I determine if a dialog has focus?
The "Selection" property of the application points to the selection in the document, even if a dialog is currently selected. I can't find any "HasFocus"-equivalent property anywhere either. I'm running out of ideas :o)
Thanks!
This workaround worked for me:
My add-in keeps a reference to the handle of the most recently activated Word window, by using the GetActiveWindow API during the WindowActivate event of the Word application. This is necessary since, up until Office 2013, the Window object does not expose a handle property.
When a shortcut is triggered, I compare that to the handle of the currently active window, using the same API. If they don't match, I simply don't proceed :o)