vb.net - 如何用vb在outlook中创建约会?

标签 vb.net outlook

我有一个 winforms 应用程序,我正在尝试创建一个方法来创建新的 Outlook 约会。 我正在使用以下代码,但在对象newAppointment的创建部分标记了一个错误。

Private Sub AddAppointment()
    Dim newAppointment As Outlook.AppointmentItem = Me.Application.CreateItem _
         (Outlook.OlItemType.olAppointmentItem)
    Try
        With newAppointment
            .Start = Date.Now.AddHours(2)
            .End = Date.Now.AddHours(3)
            .Location = "ConferenceRoom #2345"
            .Body = _
                "We will discuss progress on the group project."
            .Subject = "Group Project"
            .AllDayEvent = False
            .Recipients.Add("Roger Harui")
            Dim sentTo As Outlook.Recipients = .Recipients
            Dim sentInvite As Outlook.Recipient
            sentInvite = sentTo.Add("Holly Holt")
            sentInvite.Type = Outlook.OlMeetingRecipientType.olRequired
            sentInvite = sentTo.Add("David Junca")
            sentInvite.Type = Outlook.OlMeetingRecipientType.olOptional
            sentTo.ResolveAll()
            .Save()
            .Display(True)
        End With
    Catch ex As Exception
        MessageBox.Show("The following error occurred: " & _
            ex.Message)
    End Tryenter code here
End Sub

最佳答案

需要访问 Outlook Application 对象,因为您自己的 Application 没有合适的 CreateItem 方法:

大致如下:

Imports Microsoft.Office.Interop

....

Private Sub AddAppointment()
    '--- Check if Outlook is already up and running
    If Process.GetProcessesByName("outlook").Count > 0 Then
        '--- all ready ---
    Else
        '--- start Outlook ---
        Process.Start("outlook")
        '--- more elaborate wait might be a good idea here ---
        System.Threading.Thread.Sleep(500)
    End If

    '--- initialize required Application object ---
    '--- assuming it is not available as variable already ---
    Dim objOutlook As Outlook.Application
    objOutlook = CreateObject("Outlook.Application")

    Dim newAppointment As Outlook.AppointmentItem =
        objOutlook.CreateItem(Outlook.OlItemType.olAppointmentItem)
    Try
        With newAppointment
            .Start = Date.Now.AddHours(2)
            .End = Date.Now.AddHours(3)
            .Location = "ConferenceRoom #2345"
            .Body = "We will discuss progress on the group project."
            .Subject = "Group Project"
            .AllDayEvent = False
            .Recipients.Add("Roger Harui")
            Dim sentTo As Outlook.Recipients = .Recipients
            Dim sentInvite As Outlook.Recipient
            sentInvite = sentTo.Add("Holly Holt")
            sentInvite.Type = Outlook.OlMeetingRecipientType.olRequired
            sentInvite = sentTo.Add("David Junca")
            sentInvite.Type = Outlook.OlMeetingRecipientType.olOptional
            sentTo.ResolveAll()
            .Save()
            .Display(True)
        End With
    Catch ex As Exception
        MessageBox.Show("The following error occurred: " & ex.Message)
    End Try
End Sub

关于vb.net - 如何用vb在outlook中创建约会?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43265005/

相关文章:

vba - Outlook VBA 在 Excel 工作表中找到最后一行

vb.net - 报告查看器 - 内存不足异常

mysql - 循环在 Sub 中不断重复

vb.net - 限制vb.net中列表框中的选择

java - 如何通过 Java 从 Outlook 发送电子邮件?

c# - 在未安装 Outlook 客户端的情况下使用 Microsoft.Office.Interop.Outlook

vb.net - LINQ 查询 - 如果不匹配则抛出异常?

vb.net - vb中的微积分引擎?

html - Mailto正文不填IE

vb.net - 邮件 View Outlook 2013 Microsoft Office Interop上的奇数<end>标记