PDA

View Full Version : Automatically set zoom level to x% when an Outlook message is opened.



acantor
05-28-2014, 07:16 AM
The first thing I do when I open a message is increase the zoom level. Is there a way to do this programatically, triggered by the act of opening a message?

Similar question: can the same thing be made to happen when I give keyboard focus to a message displayed in the Reading pane?

acantor
05-29-2014, 12:34 PM
I discovered a partial solution:



' Automatic zoom changer
' Insert code in "ThisOutlookSession" module
' Set Tools > Reference to "Microsoft Word 14.0 Object Library"

Option Explicit
Dim WithEvents objInspectors As Outlook.Inspectors
Dim WithEvents objOpenInspector As Outlook.Inspector
Dim WithEvents objMailItem As Outlook.MailItem
Private Sub Application_Startup()
Set objInspectors = Application.Inspectors
End Sub
Private Sub Application_Quit()
Set objOpenInspector = Nothing
Set objInspectors = Nothing
Set objMailItem = Nothing
End Sub
Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
If Inspector.CurrentItem.Class = olMail Then
Set objMailItem = Inspector.CurrentItem
Set objOpenInspector = Inspector
End If
End Sub
Private Sub objOpenInspector_Close()
Set objMailItem = Nothing
End Sub
Private Sub objOpenInspector_Activate()
Dim wdDoc As Word.Document
Set wdDoc = objOpenInspector.WordEditor
wdDoc.Windows(1).Panes(1).View.Zoom.Percentage = 150 ' Set zoom level here
End Sub



To enable the macro, exit VBA, and exit and restart Outlook.

It works when I open (most) messages.

But it would be great if the macro was activated when I move directly from one message to the next. (In my case, I open a message in the normal way, and then press Ctrl + > to open the next message, and Ctrl + < to open the previous message.

Any thoughts on how to add this functionality?

acantor
06-05-2014, 10:33 AM
Let me try again...

There are two very useful hotkeys in Outlook that are not well known: When a message has been opened -- in other words, the message is in a window in the foreground, and Outlook is in the background -- you can "jump" to the next message by pressing

Ctrl + > (The hotkey is really Ctrl + period, but I think Ctrl + > is easier to remember)

Or you can jump to the previous message by pressing

Ctrl + < (Actually Ctrl + comma)

These hotkeys make it very fast to review one message after another, as they do away with the need to open messages by returning to the Outlook UI. There is obviously thought behind the programming of these hotkeys. For example, when you press a key to go to the previous or next message, but there are no more messages, the hotkey closes the message window and returns focus to the most recently viewed message in the Outlook UI. Nice work, Microsoft!

So back to the problem. the code (in the previous message) sets the zoom level for messages to 150%. But the macro only works if I open each message from the Outlook UI. Can anyone think of a way to either modify the macro, or come up with others, that automatically change the zoom level when I navigate from message to message via the two built in hotkeys?

skatonni
07-09-2014, 01:33 PM
Try using the selection change to Activate the mailitem.



' Automatic zoom changer
' Insert code in "ThisOutlookSession" module
' Set Tools > Reference to "Microsoft Word 14.0 Object Library"

Option Explicit

Dim WithEvents myOlExp As Outlook.Explorer ' <===

Dim WithEvents objInspectors As Outlook.Inspectors
Dim WithEvents objOpenInspector As Outlook.Inspector
Dim WithEvents objMailItem As Outlook.mailItem

Private Sub Application_Startup()
Set objInspectors = Application.Inspectors
Set myOlExp = Application.ActiveExplorer ' <===
End Sub

Private Sub Application_Quit()
Set objOpenInspector = Nothing
Set objInspectors = Nothing
Set objMailItem = Nothing
End Sub

Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
If Inspector.currentItem.Class = olMail Then
Set objMailItem = Inspector.currentItem
Debug.Print "Set objMailItem = Inspector.currentItem"
Set objOpenInspector = Inspector
End If
End Sub

Private Sub objOpenInspector_Close()
Set objMailItem = Nothing
End Sub

Private Sub objOpenInspector_Activate()
Dim wdDoc As Word.Document
Set wdDoc = objOpenInspector.WordEditor
wdDoc.Windows(1).Panes(1).View.Zoom.Percentage = 150 ' Set zoom level here
End Sub

Private Sub myOlExp_SelectionChange()
Dim currItem As mailItem
On Error Resume Next ' If there is no open mailitem.
Set currItem = Application.ActiveInspector.currentItem

objOpenInspector_Activate ' <===

End Sub

acantor
07-16-2014, 07:33 AM
Thank you!! Your code works brilliantly, both when opening messages from the main Outlook user interface, and when jumping to the next or previous message via hotkeys.

Is there a way to modify the code to increase the default zoom level in the Reading pane? Or would that be a separate macro?

By the way... after inserting (or updating) the code, I found it was necessary to exit and restart Outlook. When exiting Outlook, you will be prompted to save a file. Say Yes.

acantor
07-16-2014, 08:38 AM
I spoke too soon. Outlook is now crashing regularly. The problem happens after opening, or trying to open, email messages from the main UI. Jumping from message to message via the hotkeys seems to work fine.

I tried rebooting the computer, but the problem persists. Any thoughts on how to crashproof the code?

skatonni
07-16-2014, 09:47 AM
I spoke too soon. Outlook is now crashing regularly. The problem happens after opening, or trying to open, email messages from the main UI. Jumping from message to message via the hotkeys seems to work fine.

I tried rebooting the computer, but the problem persists. Any thoughts on how to crashproof the code?

Go to the link in my signature. Set breakpoints as described.

acantor
07-17-2014, 08:57 AM
The link to the debugging guide was helpful, but the content is mostly new to me, so I am not understanding it all.

However, I was able to step through each macro line by line. I did this two ways: with the main Outlook UI open; and with an email message opened. The results were the same both ways:

Here are my findings:

1. Nothing happens when I attempt to step through the code for this macro:

Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)

2. When I step through Private Sub objOpenInspector_Activate(), I get an error message: "Run-time error '91': Object variable or With block variable not set" on this line:

Set wdDoc = objOpenInspector.WordEditor


3. However, no error message occurs when I step through Private Sub myOlExp_SelectionChange(), which calls

objOpenInspector_Activate ' <===

So I am assuming that in the normal scheme of things, myOlExp_SelectionChange() always calls objOpenInspector_Activate.

In addition, I monitored the Immediate window while doing step by step testing, and nothing appeared in it.

Outlook did not crash during testing. However, the crashes appear to happen when I am pressing up and down arrow keys to navigate through the list of email messages in the Outlook user interface.

skatonni
07-17-2014, 10:06 AM
Set the breakpoints, then open messages, then step through where the code is yellow.

Just in case you see the error in the same place, try bypassing to see what happens.


Private Sub objOpenInspector_Activate()
Dim wdDoc As Word.Document
On Error Resume Next ' <----
Set wdDoc = objOpenInspector.WordEditor
wdDoc.Windows(1).Panes(1).View.Zoom.Percentage = 150 ' Set zoom level here
On Error GoTo 0 ' <----
End Sub

If you stop zooming while testing, run Application_Startup manually.