如何使用 Microsoft Office Outlook 2003 设置约会






4.63/5 (27投票s)
本文介绍如何使用 Microsoft Office Outlook 2003 API 创建/安排约会。
引言
使用 Microsoft Outlook 2003 发送电子邮件对于大多数 VBA 开发人员来说并非什么新鲜事。 这非常常见,也是一种很好的做法。 我希望大多数 VBA 开发人员都非常熟悉这一点。 本文不是关于如何使用 Microsoft Outlook API 从自定义 Microsoft Office 应用程序发送电子邮件,而是关于如何使用 Microsoft Outlook 2003 API 安排/设置约会。
背景
许多公司在其内部/外部办公自动化应用程序中使用 Microsoft Office 应用程序。 在本文中,我想演示如何使用 Microsoft Outlook 2003 API 设置约会。
Using the Code
使用代码非常简单。 在我们开始之前,我想分享一些我为此目的使用的 Microsoft Outlook 2003 API 对象。 对象列表如下:
对象
Outlook.Application
Outlook.Namespace
Outlook.MAPIFolder
Outlook.Recipient
Outlook.AppointmentItem
有关 Microsoft Office Outlook 2003 集成 API 参考的更多详细信息,请参见此链接。
我编写了一个非常简单的过程来执行此操作。 以下是一个示例代码:
示例代码
Public Sub myAppointment(strRecipient As String, _
strSubject As String, _
strBody As String, _
dtStartDate As Date, _
Optional intReminder As Variant, _
Optional intDuration As Variant)
'Author: Md. Marufuzzaman
'Created:
'Description: Set an appointment;
On Error GoTo ErrorHandler:
Dim ObjApplication As Outlook.Application
Dim ObjNamespace As Outlook.Namespace
Dim objFolder As Outlook.MAPIFolder
Dim ObjRecipient As Outlook.strRecipient
Dim ObjApplicationt As Outlook.AppointmentItem
Dim apptDate As Date
Dim strContact As String
Set ObjApplication = CreateObject("Outlook.Application")
Set ObjNamespace = ObjApplication.GetNamespace("MAPI")
Set ObjRecipient = ObjNamespace.CreatestrRecipient(strRecipient)
Set objFolder = ObjNamespace.GetSharedDefaultFolder(ObjRecipient, olFolderCalendar)
If Not objFolder Is Nothing Then
Set ObjApplicationt = objFolder.Items.Add
If Not ObjApplicationt Is Nothing Then
With ObjApplicationt
.strSubject = strSubject
.strBody = strBody
.Start = dtStartDate
If Not IsNull(intReminder) Then
.ReminderSet = True
.intReminderBeforeStart = intReminder
End If
If Not IsNull(intDuration) Then
.intDuration = intDuration
Else
.intDuration = 10
End If
.Save
End With
End If
End If
Set ObjApplication = Nothing
Set ObjNamespace = Nothing
Set objFolder = Nothing
Set ObjRecipient = Nothing
Set ObjApplicationt = Nothing
Exit_myAppointment:
Exit Sub
ErrorHandler:
MsgBox Err.Description, vbCritical, "Error!"
Resume Exit_myAppointment:
End Sub
结论
我希望本文对您有所帮助。 祝您愉快!
历史
- 2009年8月26日:初始发布。
- 2009年9月5日:使用 Variant 数据类型代替 Integer 类型。