0

Recently with some new Office 2016 installs, my app that interops with Outlook to attach files to emails is causing some odd UI effects preventing the email from being used. It only happens on a small percentage of users, but I can't otherwise find a pattern.

For these users, when attaching a PDF, this is the effect: Odd Email UI The To/CC/Subject fields are out of place, the rest of the email window is untypable/unclickable and the only way to do anything is to hit Escape and close the window. Using the same code, this does not happen with any other type of file than PDFs.

The code used to create the email and attach is pretty simplistic and has worked for years and years

OutlookApplication = CreateObject("Outlook.Application")

'Create a new mailItem
MailItem = OutlookApplication.CreateItem(0) '0 = olMailItem

MailItem.Subject = "Super Important Email Subject v2.0"

'Loop through each file and attach to the MailItem
For Each FilePath As String In FilePaths
    'Attach the item to the MailItem
    MailItem.Attachments.Add(FilePath)
Next

MailItem.Display()

CreateObject is being used for some backwards compatibility.

As far as I can tell, my previous 2010 and 2013 clients are not affected.

I've attempted to disable any/all addins to no effect

Brian M.
  • 826
  • 1
  • 8
  • 16

1 Answers1

-1

Try using this :

Private Sub Send_Email_Outlook(sSubject As String, sBody As String, sTo As String, sCC As String, sFilename As String, sDisplayname As String)
    Dim oApp As Outlook.Application
    'If outlook is already running then'
    If IsAppRunning("Outlook.Application") = True Then
        'Get outlook object'
        oApp = GetObject(, "Outlook.Application")
    Else  'Else Create it'
        oApp = New Outlook.Application
    End If

    Dim ns As Outlook.NameSpace = oApp.GetNamespace("MAPI")
    Dim f As Outlook.MAPIFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox)
    Dim oMsg As Outlook.MailItem
    oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
    Dim oInspector As Outlook.Inspector = oMsg.GetInspector
    oApp.ActiveWindow.WindowState = FormWindowState.Minimized
    oMsg.Subject = sSubject
    oMsg.Body = sBody
    oMsg.To = sTo
    If sCC <> "" Then
        oMsg.CC = sCC
    End If
    If sFilename <> "" Then
        Dim sBodyLen As Integer = Int(sBody.Length)
        Dim oAttachs As Outlook.Attachments = oMsg.Attachments
        Dim oAttach As Outlook.Attachment
        For Each file1 In sFilename.Split(";")
            oAttach = oAttachs.Add(file1, , sBodyLen, sDisplayname)
        Next
    End If
    oMsg.Display()
    ns.SendAndReceive(False)
    If Not IsNothing(ns) Then Marshal.ReleaseComObject(ns)
    oMsg = Nothing
End Sub
  • Other than just copying/pasting a slightly different way... what part in here is possibly impactful to the problem? – Brian M. Sep 28 '17 at 17:04