【问题标题】:Outlook Appointment isn't showing Attendees that have been addedOutlook 约会未显示已添加的与会者
【发布时间】:2020-10-28 16:21:10
【问题描述】:

我在使用来自网络的科学怪人的一些代码时遇到了一些问题。我有一个 Word 文档,它使用命令按钮运行一段代码,最终结果是生成了一个添加了模板的 Outlook 约会以及收件人。我使用了 2 种不同的方法,每种方法都有自己的问题。

方法 1:生成约会,包括并显示与会者,但不允许正文的 HTML 格式


Dim xOutlookObj As Object
Dim OMail As Object
Dim xMeeting As Object
Dim xDoc As Object
Dim myRequiredAttendee As Outlook.Recipient
Dim myOptionalAttendee As Outlook.Recipient
Application.ScreenUpdating = False

Set xOutlookObj = CreateObject("Outlook.Application")
Set xEmail = xOutlookObj.CreateItem(olMailItem)
Set xDoc = ActiveDocument
opCancel = False

Set xOutlookObj = CreateObject("Outlook.Application")
Set xMeeting = xOutlookObj.CreateItem(olAppointmentItem)
Set myRequiredAttendee = xMeeting.Recipients.Add(EMAIL ADDRESSES)
myRequiredAttendee.Type = olRequired
Set xDoc = ActiveDocument

With xMeeting
    .MeetingStatus = olMeeting
    .Display
    .Subject = "MEETING SUBJECT"
    .Duration = 60
    .Body = "MESSAGE BODY THAT I'D LIKE TO FORMAT, BUT THIS METHOD DOESN'T PERMIT HTML"

End With

Set xDoc = Nothing
Set xMeeting = Nothing
Set xOutlookObj = Nothing
Application.ScreenUpdating = True

方法 2:生成约会,允许对正文进行 HTML 格式设置,加载与会者但不显示他们。当我单击邀请中的“邀请与会者”按钮时,它们都会出现(因此它们显然正在被加载)。

Dim olapp As Outlook.Application, appt As Outlook.AppointmentItem
Dim m As Outlook.MailItem
Dim rtf() As Byte

Set olapp = New Outlook.Application
Set m = olapp.CreateItem(olMailItem)
Set appt = olapp.CreateItem(olAppointmentItem)

appt.Display
appt.Subject = "MEETING SUBJECT"
appt.Duration = 60
appt.RequiredAttendees = "EMAIL ADDRESSES"

m.BodyFormat = olFormatHTML
m.HTMLBody = "<font style=""color: red;"">VERIFY SUBJECT LINE & MEETING START TIME ARE CORRECT, THEN DELETE THIS LINE" & _
        "<font style=""color: black;""><p>REST OF TEXT BODY</P>
m.GetInspector().WordEditor.Range.FormattedText.Copy
appt.GetInspector().WordEditor.Range.FormattedText.Paste
m.Close False 'don't save...

我正在寻找的是创建约会、加载和显示与会者、并允许 HTML 格式化正文的代码。另外,我不能使用 .send 命令,因为在发送之前仍然需要编辑邀请的正文 - 这就是为什么我希望显示与会者以避免混淆。

谢谢!

【问题讨论】:

    标签: vba outlook appointment


    【解决方案1】:

    #1 很好,但 AppointmentItem 对象不直接支持 HTML - 你得到纯文本 Body 属性或 RTF 格式(字节数组)RtfBody 属性。您需要生成适当的 RTF,或者使用 AppointmentItem.GetInspector().WordEditor(返回 Word 的 Document 对象)来生成格式适当的正文。

    【讨论】:

    • 要明确一点——只有 1 个或另一个会运行(不能同时运行)。首先回答您对 #2 的评论 - 我不确定它是如何做到的,但最终结果与 #1 几乎相同 - 使用格式化文本生成约会(顶行为红色,其余为黑色),并且与会者已加载 - 他们只是没有显示。至于#1 - 你能帮我“生成适当的RTF”或文字编辑器位吗?谢谢!
    • 您是否尝试过使用appt.Recipients.AddRecipient 一次添加一位与会者?
    • 我刚刚调整了#2,我得到一个运行时错误 438 - 对象不支持这个属性或方法
    • 对不起,应该是appt.Recipients.Add("user@domain.demo")
    【解决方案2】:

    让它与以下小调整一起工作 - Dmitry 的道具让我再次查看 GetInspector().WordEditor 部分。以下代码生成约会、加载收件人并显示他们,以及将邮件正文格式化为 HTML。

    Dim xOutlookObj As Object
    Dim OMail As Object
    Dim xMeeting As Object
    Dim xDoc As Object
    Dim myRequiredAttendee As Outlook.Recipient
    Dim myOptionalAttendee As Outlook.Recipient
    Application.ScreenUpdating = False
    
    Set xOutlookObj = CreateObject("Outlook.Application")
    Set xEmail = xOutlookObj.CreateItem(olMailItem)
    Set xDoc = ActiveDocument
    
    Set xOutlookObj = CreateObject("Outlook.Application")
    Set xMeeting = xOutlookObj.CreateItem(olAppointmentItem)
    Set myRequiredAttendee = xMeeting.Recipients.Add(EMAIL LIST)
    myRequiredAttendee.Type = olRequired
    Set xDoc = ActiveDocument
    
    With xMeeting
        .MeetingStatus = olMeeting
        .Display
        .Subject = "MEETING SUBJECT"
        .Duration = 60
        **xEmail.BodyFormat = olFormatHTML
        xEmail.HTMLBody = "<font style=""color: red;"">VERIFY SUBJECT LINE & MEETING START TIME ARE CORRECT, THEN DELETE THIS LINE" & _
            "<font style=""color: black;""><p>THE REST OF APPT MESSAGE</p>"
        xEmail.GetInspector().WordEditor.Range.FormattedText.Copy
        xMeeting.GetInspector().WordEditor.Range.FormattedText.Paste**
    End With
    
    Set xDoc = Nothing
    Set xMeeting = Nothing
    Set xOutlookObj = Nothing
    Application.ScreenUpdating = True
    

    抱歉 - 我不经常发布此类格式的帖子,而且我不知道为什么上面带有双 ** 的部分没有加粗。粗体部分是我为使这项工作所做的更改 - 如果有人可以纠正它,我将不胜感激。

    干杯!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-14
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 2013-02-03
      • 1970-01-01
      相关资源
      最近更新 更多