gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 03:42:50 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com