【问题标题】:How to create an appointment in outlook with vb?如何用vb在outlook中创建约会?
【发布时间】:2017-04-08 11:21:04
【问题描述】:

我有一个 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

【问题讨论】:

    标签: vb.net outlook


    【解决方案1】:

    需要访问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
    

    【讨论】:

    • 谢谢你的帮助,原来是这样,你救了我
    【解决方案2】:

    这可能与您最初的想法有所不同,但我认为它将帮助您朝着正确的方向开始。

    如果您想使用 Excel 在 Outlook 中创建约会,请运行以下脚本(在 Excel 中)。

    Private Sub Add_Appointments_To_Outlook_Calendar()
    
        'Include Microsoft Outlook nn.nn Object Library from Tools -> References
        Dim oAppt As AppointmentItem
        Dim Remind_Time As Double
    
        i = 2
        Subj = ThisWorkbook.Sheets(1).Cells(i, 1)
    
        'Loop through entire list of Reminders to be added
        While Subj <> ""
            Set oAppt = Outlook.Application.CreateItem(olAppointmentItem)
    
            oAppt.Subject = Subj
            oAppt.Location = ThisWorkbook.Sheets(1).Cells(i, 2)
            oAppt.Start = ThisWorkbook.Sheets(1).Cells(i, 3)
            Remind_Time = ThisWorkbook.Sheets(1).Cells(i, 4) * 1 * 60
            oAppt.ReminderMinutesBeforeStart = Remind_Time
            oAppt.AllDayEvent = True
            oAppt.Save
    
            i = i + 1
            Subj = ThisWorkbook.Sheets(1).Cells(i, 1)
        Wend
        MsgBox "Reminder(s) Added To Outlook Calendar"
    
    End Sub
    

    ' 代码来自这个链接: http://officetricks.com/add-appointment-to-outlook-calendar-through-excel-macro-vba/

    这是设置应该是什么样子的屏幕。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-20
      • 1970-01-01
      相关资源
      最近更新 更多