Hotkey for moving messages from inbox to archive in Outlook - vba

I'd like to configure a hotkey, in MS Outlook, which does the following to the highlighted/selected messages:
Mark as read (by default it's [crtl]+Q)
Move to an "archive" folder (archive meaning a folder other than the default inbox)
This should happen whenever I press [crtl]+M (assuming it is not already reserved), on any amount of messages I select.
I currently use Outlook 2007.

It might be difficult to assign a Hotkey to a Macro in Outlook, but you can add the Macro as a button in the toolbars.

Related

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

Purge an IMAP folder in Outlook 2016 using 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

Tracking open Outlook 2010 emails

I'm looking for a programmatic way (eg: using VBA) to write the Subject texts of emails which are open, or otherwise export opened emails to a file system folder.
Trap the Application.Inspectors.NewInspector event an read the Inspector.CurrenmtItem.Subject property. Reading pane needs to be handled separately.

Hotkey to run macro when viewing the email

I have a macro that sends a reply to email selected in the inbox. I assigned it to the Quick Access Toolbar and run it by pressing alt+1.
The hotkey does not work when I view the email itself (I sometimes open it from within a task). In email view I can go to the macros ribbon and run it manually and it works, but I can't find the way to run it with the hotkey. Any suggestions?
I need to view email and decide if I run the reply macro or not, so a solution to run it on open action won't work.
edit: solution i comments
There is a separate Quick Access Toolbar for open mailitems. If the 1 is over the Save icon, you are currently saving with Alt+1.
If the code can process ActiveInspector.CurrentItem then you can add the macro.

Outlook 2007 VBA code to jump to (open) IMAP Inbox

I am using Outlook to sync mail with GMail via IMAP.
Outlook's default shortcut to go to the Inbox (Shift + Ctrl + I) opens the original Inbox, not the new default IMAP Inbox (which I have specified as the new Outlook default e-mail account).
I would like to create VBA code that I can bind to another keystroke, which will open the IMAP Inbox.
I think the only way to do this would be to create a button on the toolbar that searches for your IMAP folder and calls display on it.
Then you can assign a keyboard shortcut to that button and use that.
the other way would be to use winapi to hook the shortcut and call you search and display.
76mel
-right-click DESKTOP
-click NEW > SHORTCUT
-for OUTLOOK 2003 type (including the double-quotes): "C:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE" Outlook://SUBSTITUTE-OUTLOOK-INBOX-NAME-HERE/Inbox
-for OUTLOOK 2007 type (including the double-quotes): "C:\Program Files\Microsoft Office\OFFICE12\OUTLOOK.EXE" Outlook://SUBSTITUTE-OUTLOOK-INBOX-NAME-HERE/Inbox
Hoping that this is still relevant to someone; adding to dakruhm's answer:
It's best to add the /recycle switch to the command. That way, if Outlook is open, a new Outlook window will NOT be created. (Use that unless you WANT one to be created.)
The command (for Outlook 2007) therefore looks as follows:
"C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE" /recycle Outlook://Gmail IMAP/Inbox
Also, dakruhm's answer was very detailed, but he forgot to mention that you need to assign a shortcut key. I've checked this, and if you use Ctrl + Shift + I, there seems to be a delay until the command is carried out. I therefore use Ctrl + Alt + I, which takes some getting used to, but works much quicker.