NOTE:
Due to data loss with OfficeZealot’s blog server, all comments posted between April 28 and June 8 , 2005 to any of my blog entries were inadvertently deleted. The end of this blog entry contains the text of the comments applicable to this posting that I was able to recover.
UPDATED Oct. 26, 2004
(As per Ryan’s helpful suggestion below, I’ve added another procedure; updates appended to the end of this blog post)
Have you ever tried responding to a very long e-mail, and you find yourself either ALT-Tabbing back to the original, or scrolling down in your reply message to constantly refer to certain parts of the text? Sure, you can find the original message, open it and tile that window with your reply window horizontally/vertically. But we want a one-click solution! So here’s some VBA and Win32 API code to do just that. This macro is meant to be run with your e-mail reply already open, and it assumes the message you are replying to is selected in your main Outlook window. Put this code into a new module in your Outlook VBA project, and associate it with a button on your new message form:
Option Explicit
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End TypePublic Const SPI_GETWORKAREA = 48
Declare Function SystemParametersInfo Lib “user32” Alias “SystemParametersInfoA” (ByVal uAction As Long, _
ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As LongSub ShowReplyMessage()
On Error GoTo EH:Dim objReply As Inspector
Dim objMessage As Object
Dim objMessageI As Inspector
Dim lRet As Long
Dim apiRECT As RECTIf ActiveExplorer.Selection.Count > 1 Then Exit Sub
Set objMessage = ActiveExplorer.Selection.Item(1)
Set objReply = Application.ActiveInspector
Set objMessageI = objMessage.GetInspectorobjMessage.Display
objMessageI.WindowState = olNormalWindowlRet = SystemParametersInfo(SPI_GETWORKAREA, vbNull, apiRECT, 0)
If lRet Then
objMessageI.Top = 0
objMessageI.Left = 0
objMessageI.Height = (apiRECT.Bottom – apiRECT.Top) / 2
objMessageI.Width = apiRECT.Right – apiRECT.LeftobjReply.Display
objReply.WindowState = olNormalWindow
objReply.Top = (apiRECT.Bottom – apiRECT.Top) / 2
objReply.Left = 0
objReply.Height = (apiRECT.Bottom – apiRECT.Top) / 2
objReply.Width = apiRECT.Right – apiRECT.Left
End IfLeaving:
Set objMessage = Nothing
Set objMessageI = Nothing
Set objReply = NothingEH:
If Err.Number <> 0 Then
MsgBox “Something wrong has happened!”, vbOKOnly + vbExclamation, “UNKNOWN ERROR”
Err.Clear
GoTo Leaving:
End If
End Sub
Update:
This alternate procedure does not depend on you having your reply e-mail already open. This macro is suitable to be called from your main Outlook window. Just select the original e-mail in the folder and run the macro – it will open up the original message, and automatically create your reply message and tile both windows for you. If you use just this procedure, make sure to add the same module level declarations as above:
Sub ReplyAndShowReferringMessage()
On Error Resume NextDim objReply As Object
Dim objReplyI As Inspector
Dim objMessage As Object
Dim objMessageI As InspectorIf ActiveExplorer.Selection.Count > 1 Then Exit Sub
Set objMessage = ActiveExplorer.Selection.Item(1)
Set objReply = ActiveExplorer.Selection.Item(1).ReplyobjMessage.Display
Set objMessageI = objMessage.GetInspector
objMessageI.WindowState = olNormalWindow
‘H: 723 L: -4 T: -4 W: 1032
Dim lRet As Long
Dim apiRECT As RECTlRet = SystemParametersInfo(SPI_GETWORKAREA, vbNull, apiRECT, 0)
If lRet Then
objMessageI.Top = 0
objMessageI.Left = 0
objMessageI.Height = (apiRECT.Bottom – apiRECT.Top) / 2
objMessageI.Width = apiRECT.Right – apiRECT.LeftobjReply.Display
Set objReplyI = objReply.GetInspector
objReplyI.WindowState = olNormalWindow
objReplyI.Top = (apiRECT.Bottom – apiRECT.Top) / 2
objReplyI.Left = 0
objReplyI.Height = (apiRECT.Bottom – apiRECT.Top) / 2
objReplyI.Width = apiRECT.Right – apiRECT.Left
Else
‘DO NOTHING; Call to SystemParametersInfo failed
End IfSet objReply = Nothing
Set objReplyI = Nothing
Set objMessage = Nothing
Set objMessageI = Nothing
End Sub
—————————————————————-
COMMENTS RESTORED FROM BACKUP:
Mon 6/6/2005 8:32 PM Jimmy
How can I rename the button … as of now it reads Project1.ReplyAndShowReferringMessage … It takes up a quarter of my toolbar. Any help would be much appreciated.
Mon 6/6/2005 8:44 PM Jimmy
The piece of code below vertically aligns the two windows:
If lRet Then
objMessageI.Top = 0
objMessageI.Left = (apiRECT.Right – apiRECT.Left) / 2
objMessageI.Height = apiRECT.Bottom – apiRECT.Top
objMessageI.Width = (apiRECT.Right – apiRECT.Left) / 2
objReply.Display
Set objReplyI = objReply.GetInspector
objReplyI.WindowState = olNormalWindow
objReplyI.Top = 0
objReplyI.Left = 0
objReplyI.Height = apiRECT.Bottom – apiRECT.Top
objReplyI.Width = (apiRECT.Right – apiRECT.Left) / 2
Else
END COMMENTS RESTORE
—————————————————————-
You must log in to post a comment.