none
Outlook New Message from VBA display glitch RRS feed

  • Question

  • Hello, 

    Whenever I try to generate a new message from Excel using a VBA script, I encounter the following glitch:

    Additional blank boxes appear over the TO, CC, and Subject lines on the new message. At this point, I am unable to send out the email. I would post up an image, however, my account hasn't been verified yet.

    I've noticed that this issue started occurring earlier this month, I also tested this on several computers and the results were the same. 

    Here is my current Office Build: 

    Version 1707 (Build 8326.2076 Click-to-Run) 

    Note - I've experimented with the VBA script and discovered that if you remove the .Attachments.Add command, the newly generated email does not produce the glitch. However, I would like to have this functionality working again. 

    Any thoughts? 


    • Edited by Danjinkiez Wednesday, August 23, 2017 3:57 PM
    • Moved by Steve Fan Thursday, August 24, 2017 5:52 AM relocate
    Wednesday, August 23, 2017 3:57 PM

All replies

  • Hi,

    From the description, the issue is more likely related to the VBA script. I'll move it to the Outlook for Developers forum so that you will get more dedicated assistance:

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=outlookdev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Regards,

    Steve Fan


    Please remember to mark the replies as answers if they helped.

    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Thursday, August 24, 2017 5:52 AM
  • Hi Danjinkiez,

    I failed to reproduce your issue with below code. Could you share us your code?

    Sub FromExcel()
    
    Dim olapp As Outlook.Application
    
    Set olapp = CreateObject("outlook.application")
    
    FilePath = "C:\Users\Administrator\Desktop\PivotTablesAndCharts.xlsm"
    
    Set mail = olapp.createitem(olMailItem)
    
    mail.Attachments.Add (FilePath)
    
    mail.Display
    
    End Sub

    I suggest you share screenshots via One Drive and then put link here so we could try to reproduce your issue.

    If you use below code to generate a new message from outlook, would you still encounter this  glitch?

    Sub FromOutlook()
    
    Dim mail As MailItem
    
    Path = "C:\Users\Administrator\Desktop\PivotTablesAndCharts.xlsm"
    
    Set mail = Application.CreateItem(olMailItem)
    
    mail.Attachments.Add (Path)
    
    mail.Display
    
    End Sub

    Best Regards,

    Terry

    Friday, August 25, 2017 8:51 AM
  • Here's a screen shot of the glitch: 

    And here is the code that's being used to generate the new email: 

    Dim ola As Outlook.Application
    Dim maiMessage As Outlook.MailItem
    Dim strToEmails As String
    Dim strCCEmails As String
    
    Set ola = New Outlook.Application
    Set maiMessage = ola.CreateItem(olMailItem)
    With maiMessage
        'Enter To Recipients for Email
            For Each Item In Range("Data!Email_To_Recipients")
                strToEmails = strToEmails & ";" & Item
            Next
            .To = strToEmails
        'Enter CC Recipients for Email
         For Each Item In Range("Data!Email_CC_Recipients")
                strCCEmails = strCCEmails & ";" & Item
            Next
            .CC = strCCEmails
       'Enter subject in Email Message
       If Range("Data!UseStandardSubject").Value = True Then
            .Subject = strProject & ": " & strTrade & " Daily Report " & strDATE
            
        Else
            .Subject = Range("Data!Email_Subject").Value
        End If
        
        'Attach Daily
        .Attachments.Add Source:=strFilename
        'Add Message Text (Standard Message or Custom)
        If Range("Data!UseStandardEmail").Value = True Then
            .Body = "Attached is the " & strTrade & " Daily Report for " & strDATE & " at " & strProject & ". Please let me know if you have any questions." & vbCr & vbCr & "Thank you."
        Else
            .Body = Range("Data!Email_Message").Value
        End If
        
        .Display
    End With
    
    I tried running the script again today on two different computers and it appears to be working just fine. This problem seems to be intermittent and occurs at random times. 


    Monday, August 28, 2017 6:57 PM
  • Hi Danjinkiez,

    I could still not reproduce your issue. Your code seems to be a snippet, I suggest you test if other code has effect on your issue. Besides, there are multiple updates in August, you could try to update to last version(8326.2087) or revert to a previous version to check if the issue still exists.

    Best Regards,

    Terry

    Tuesday, August 29, 2017 8:54 AM
  • I am experiencing exactly the same behavior with Outlook build 8326.2096.  It doesn't matter what application the VBA code is called from.  A workaround is to call the Save method on the olmailitem before calling the Display method.  However this has the potentially undesirable side effect of saving a copy of the message in the user's Drafts folder.

    Here's my Code:

    Public Sub EmailQuote(parQuoteNo As String)
    If GetQuote(parQuoteNo) Then
        FileName = Environ("TEmp") & "\" & Session.cCompanyName & " Quote " & parQuoteNo & " Rev " & rsQuote!frevno & ".htm"
        writehtml (FileName)
        Dim objOLApp As Object
        Dim NewMessage As Object
        Set objOLApp = CreateObject("Outlook.Application")
        Set NewMessage = objOLApp.CreateItem(olmailitem)
        ema = ContactEmailAddress
        If ema <> "" Then NewMessage.To = ema
        NewMessage.Subject = Session.cCompanyName & " Quotation " & parQuoteNo & " Rev " & rsQuote!frevno
        NewMessage.body = "palceholder" 'Prevents attachment from becoming body of message if format is html
        NewMessage.Attachments.ADD FileName, olByValue, 1, "Quotation " & parQuoteNo
        NewMessage.body = ""
        NewMessage.Display (False)
        Set objOLApp = Nothing
        Set NewMessage = Nothing
        Kill FileName
    End If
    If rsQuote.State = adstateopen Then rsQuote.Close
    Set rsQuote = Nothing
    
    End Sub

    And here's a screenshot of the glitch:

    Screenshot

    Wednesday, August 30, 2017 1:59 PM
  • We're also seeing the exact same behavior (unfortunately I cannot add images or links as MS claims my account is unconfirmed, so you will have to trust me :-))

    We find that it is reproducible on build 1707 and onward:

    Below are two subs of which the first produces the problem and the second works around the problem: It adds the attachment AFTER the .Display call to alleviate the problem. This appears to be a bug in Outlook.

    Public Sub CreateMailGivesGhostTextboxes()

         Set olkApp = CreateObject("outlook.application")

         With olkApp.createitem(0)

             .To = "someone[at]somewhere[dot]com"

             .Subject = "The subject"

             .body = "Some body"

             .attachments.Add "C:\x\somefile.txt" 'ActiveDocument.FullName

             .Display

         End With

         Set olkApp = Nothing

    End Sub

     

     Public Sub CreateMailOk()

         Set olkApp = CreateObject("outlook.application")

         With olkApp.createitem(0)

           

             .To = "someone[at]somewhere[dot]com"


             .Subject = "The subject"

             .body = "Some body"

           

             .Display

             .attachments.Add "C:\x\somefile.txt" 'ActiveDocument.FullName

         End With

         Set olkApp = Nothing

    End Sub

     



    • Edited by MiThBa Tuesday, November 28, 2017 1:49 PM
    • Proposed as answer by Terry Xu - MSFT Wednesday, November 29, 2017 2:12 AM
    Tuesday, November 28, 2017 12:00 PM
  • I experienced the exact same glitch with this python code-

    def Emailer(text, subject, recipient, attachments):
        import win32com.client as win32
        outlookapp = win32.Dispatch('outlook.application')
        mail = outlookapp.CreateItem(0)
        for a in attachments:
            mail.Attachments.Add(Source=a)
        mail.To = recipient
        mail.Subject = subject
        mail.HTMLBody = text
    
        mail.Display()
    	
    Emailer("test123", "This is an auto-generated email", "my_email@gmail.com", ["D:\\data\\my_attachment.txt"])

    the problem was solved when I added the line :

    mail.Save()

    before the line:

    mail.Display()
    

    Thursday, February 22, 2018 11:22 AM
  • I tested the above said scenario with Outlook 2016 (1804 build). I failed to repro the issue. So try to get the latest Outlook build and make sure it has build number above 1804 and test it.



    DeVa, M.S., {MSFT} Please remember to mark the replies as answers if they help

    Friday, May 4, 2018 10:10 PM
  • I've had this same issue too. It seems to be a problem with adding an attachment while the MailItem object is not visible.

    I have found that if you add the attachment AFTER you have displayed, no visual bugs happen.

    OutMail.Display

    OutMail.Attachments.Add Path

    • Proposed as answer by kmcdowell Thursday, July 12, 2018 1:54 PM
    Thursday, July 12, 2018 1:53 PM