Outlook Mail Window - Buggy Overlay

Krayons

Board Regular
Joined
Sep 9, 2016
Messages
232
Hey guys,

As of late, I've been having some strange issue when generating Outlook Mail windows through VBA.

Has anyone ever encountered a situation where there was some overlay issue? Anytime an email window is created and shown using .display, I cannot press send, or otherwise interact with anything on the window. If I hover over the input fields, some new ones appear ontop of everything else -- those inputs I am able to interact with.

Anyone have any ideas what may be causing this behaviour? Below is the code I use to generate these emails -- pretty standard stuff.

Code:
' defined at the beginning of my code
Dim olApp As Object
Dim olMail As Object
Set olApp = CreateObject("Outlook.Application")

' there are 4 other code blocks that appear like this
Set olMail = olApp.CreateItem(0)

With olMail
    .To = "example@email.com"
    .Subject = "SA3 Reports"
    .Body = "Hello," & vbCr & vbCr _
    & "Please review the attached SA3 Reports for your stores." & vbCr & vbCr _
    & "Thank you," & vbCr _
    & "Your Payroll Team"

    For Each wgStore In wgGroup
        Filename = ThisWorkbook.path & "\SA3 Splits\SA3 Report - " & wgStore & ".xlsx"
        If Not Dir(Filename, vbDirectory) = vbNullString Then
            .Attachments.Add Filename
        End If
    Next wgStore

    .Display
End With

Set olMail = Nothing

And here is a screen grab of the issue:

Inked_Screenshot_2017_08_11_15_38_01_LI.jpg


I appreciate any feedback or suggestions anyone can offer.

Thank you.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Turns out it was the act of adding attachments that were causing the GUI issues. The solution that worked for me, was to create the mail item, display it first and then add attachments.

As an example (note, it doesn't matter if you late bind or early bind):

Code:
Dim olApp As New Outlook.Application
Dim exampleMail As Outlook.MailItem: Set exampleMail = olApp.CreateItem(olMailItem)
Dim exampleFiles As Outlook.Attachments: Set exampleFiles = exampleMail.Attachments

With exampleMail
        .To = "example@email.com"
        .Subject = "Example Subject"
        .BodyFormat = olFormatHTML
        .HTMLBody = "Hello, This is an example."
        .Display
    End With

Filename = "C:\SomeFolder\someFile.xlsx"

exampleFiles.Add Filename

Hope this helps someone.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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