Code to place outlook email window on screen

DougRobertson

Active Member
Joined
Sep 22, 2009
Messages
334
Office Version
  1. 365
Platform
  1. Windows
Hello,

I use a macro to generate emails for various reports I send, but I want to have the email window show up in a specific place on the screen - in 'normal' mode.

Here's the code I'm trying to accomplish it with. The screen-sizing section works when using a macro to resize excel windows, but not Outlook email windows.

Sub Macro1()
'
' Macro1 Macro
'
Set otlApp = CreateObject("Outlook.Application")
Set otlNewMail = otlApp.CreateItem(otlMailItem)
With otlNewMail
.To = "YOU"
.Subject = "BROADCAST ANALYSIS REPORT"
.Body = Chr(14) & "Hello Everyone!"
.Display
.Application.ActiveWindow.WindowState = 2

With ActiveWindow
.Top = 3
.Left = 2.2
.Width = 600
.Height = 300
End With

End With
End Sub

Thanks in advance,

~ Doug
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
It appears that the macro's grabbing the Excel window, not the outlook mailitem macro: Running the slightly modified code below gives me an output of "Book1" for the name of the activeWindow. (and then it fails on the .top = 3 line)

Code:
Sub Macro1()
'
' Macro1 Macro
'
    Dim otlapp                      As Object
    Dim otlnewmail                  As Object
    Dim W
    Set otlapp = CreateObject("Outlook.Application")
    Set otlnewmail = otlapp.CreateItem(0)
    With otlnewmail
        .To = "YOU"
        .Subject = "BROADCAST ANALYSIS REPORT"
        .Body = Chr(14) & "Hello Everyone!"
        .Display
        .Application.ActiveWindow.WindowState = 2
        With ActiveWindow
            MsgBox .Caption
            .Top = 3
            .Left = 2.2
            .Width = 600
            .Height = 300
        End With
    End With
End Sub

This code seems to do what you want, although I've had problems in the past using ActiveWindow type things with outlook. (nothing like having a meeting reminder popping up causing a code failure...)

Code:
Sub MacroFixedMaybe()
'
' Macro1 Macro
    Dim otlapp                      As Object
    Dim otlnewmail                  As Object
    Set otlapp = CreateObject("Outlook.Application")
    Set otlnewmail = otlapp.CreateItem(0)
    With otlnewmail
        .To = "YOU"
        .Subject = "BROADCAST ANALYSIS REPORT"
        .Body = Chr(14) & "Hello Everyone!"
        .Display
        .Application.ActiveWindow.WindowState = 2
    End With
    With otlapp.ActiveWindow
        .Top = 3
        .Left = 2.2
        .Width = 600
        .Height = 300
    End With
End Sub
 
Upvote 0
. . . . by George - you've got it!!

I've been looking for that for MONTHS.

Thanks Chris!

Blessings on you,

~ Doug
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,555
Members
452,928
Latest member
101blockchains

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top