PDA

View Full Version : Open all emails in specified location and size (on loading only)



SimonHughes
04-06-2019, 06:24 AM
I would like to open emails (both new or received) in an inspector window with specific location and a specific size regardless of the locations of previously opened and closed emails.

I have the code to re-size and re-position but what I'm lacking is which event I should put the code in. My best attempt results in the email behaving as desired the first time it loads into the window. However if I then manually re-size or re-position it and switch to another window and back it will re-size / re-position again. I only want it when it loads. Here is the code:


Public WithEvents objInspectors As Outlook.Inspectors
Public WithEvents objMailInspector As Outlook.Inspector



Private Sub Application_Startup()
Set objInspectors = Outlook.Application.Inspectors
End Sub


Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
'Specify the message window
If TypeOf Inspector.CurrentItem Is MailItem Then
Set objMailInspector = Inspector
End If
End Sub


Private Sub objMailInspector_Activate()


With objMailInspector
.WindowState = olNormalWindow
.Top = -1
.Left = 4655
.Width = 657
.Height = 1041
End With


End Sub


So my question is which event I should put it in? Thanks!

Microsoft Outlook for Office 365 MSO (16.0.11029.20045) 32-bit
MS Outlook version 1811

SimonHughes
04-06-2019, 07:59 AM
I may have solved with a slightly hacky solution, adding the blnLoading boolean (see below). I will test it for a bit before marking solved. Would be interesting to know that 'on activate for first time' event though:


Public WithEvents objInspectors As Outlook.Inspectors
Public WithEvents objMailInspector As Outlook.Inspector
Public blnLoading As Boolean




Private Sub Application_Startup()
Set objInspectors = Outlook.Application.Inspectors
End Sub


Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
'Specify the message window
If TypeOf Inspector.CurrentItem Is MailItem Then
Set objMailInspector = Inspector
blnLoading = True

End If
End Sub


Private Sub objMailInspector_Activate()


If blnLoading = True Then
With objMailInspector
.WindowState = olNormalWindow
.Top = -1
.Left = 4655
.Width = 800
.Height = 1041
End With
SendKeys "%7"
End If
blnLoading = False

End Sub