vba - Outlook.MailItem - 方法 "To"失败 Outlook 2013

标签 vba outlook outlook-2010

我使用“ThisOutlookSession”和表单“UserFormWorkTime”。

使用 Outlook 2010 没有任何问题。但现在使用 Outlook 2013, 我收到以下错误:

Error

这是我的代码:

'Benutzername für E-Mail auslesen
'MsgBox Session.Accounts.Item(1).UserName
Var = Split(Session.Accounts.Item(1).UserName, ".")
Vorname = Var(0)
Name = Var(1)

' E-Mail erstellen und anzeigen
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)

If TextBoxInputWorkStart = "" Then

    With objMail
      .To = TextBoxInputTo
      .CC = TextBoxInputCC
      .Subject = "Arbeitszeit " + TextBoxInputDate + ""
      .HTMLBody = "Sehr geehrte Damen und Herren," & "<br><br>" & "aufgrund " & TextBoxInputReason & " war keine Zeiterfassung möglich." & "<br><br>" & "Ende: " & TextBoxInputWorkEnd & "<br><br>" & "Vielen Dank für das Eintragen" & "<br>" & Vorname & " " & Name
      ' A dialog box is open. Close it and try again => avoid this error, display it modelessly
      Unload Me
      objMail.Display

    End With

最佳答案

一些事情。

1) 如果这是 Outlook VBA 并且您正确使用 ThisOutlookSession,则无需 设置 objOutlook = CreateObject("Outlook.Application")

2) 始终使用 & 连接字符串,不要使用 +

3) 不要将对象与其 .Text 值混为一谈。使用 TextBoxInputDate.Text 代替 TextBoxInputDate

尝试以下稍作修改的代码:

Dim objMail As MailItem
' E-Mail erstellen und anzeigen

Set objMail = ThisOutlookSession.CreateItem(olMailItem)

With objMail
    .To = TextBoxInputTo.Text
    .CC = TextBoxInputCC.Text
    .Subject = "Arbeitszeit " & TextBoxInputDate.Text & ""
    .HTMLBody = "Sehr geehrte Damen und Herren," & "<br><br>" & "aufgrund " & TextBoxInputReason.Text & " war keine Zeiterfassung möglich." & "<br><br>" & "Ende: " & TextBoxInputWorkEnd.Text & "<br><br>" & "Vielen Dank für das Eintragen" & "<br>" & Vorname & " " & Name
    ' A dialog box is open. Close it and try again => avoid this error, display it modelessly
    Unload Me
    objMail.Display
End With

关于vba - Outlook.MailItem - 方法 "To"失败 Outlook 2013,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31448159/

相关文章:

html - Outlook 2010 中的宽度问题

javascript - setSubmitMode 方法在用户之间表现不同

excel - 在所有工作表中应用按钮+宏

excel - 如何在 case 语句中定义范围?

java - 使用 JavaMail 创建带有附件的 EML 文件

c# - 从 Outlook 获取附件

silverlight - 从 Outlook 拖放到 Silverlight 应用程序

vba - 使用Evaluate比较date类型和int类型

excel - PowerShell 数据集到 Excel 的性能提升

vba - 循环通过 Outlook 项目的运行时错误