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