我使用“ThisOutlookSession”和表单“UserFormWorkTime”。
使用 Outlook 2010 没有任何问题。但现在使用 Outlook 2013, 我收到以下错误:
这是我的代码:
'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/