最近,随着一些新的Office 2016安装,我的应用程序与Outlook交互以将文件附加到电子邮件,导致一些奇怪的UI效果阻止电子邮件被使用。它只发生在一小部分用户身上,但我无法找到模式。
对于这些用户,在附加PDF时,这是效果: To / CC / Subject字段不合适,电子邮件窗口的其余部分是不可打印/不可点击的,唯一的方法是点击Escape并关闭窗口。使用相同的代码,不会发生在除PDF之外的任何其他类型的文件中。
用于创建电子邮件和附件的代码非常简单,并且已经使用了数年和数年
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正用于向后兼容。
据我所知,我之前的2010年和2013年的客户都没有受到影响。
我试图禁用任何/所有插件无效
答案 0 :(得分:-1)
尝试使用:
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