|
RefreshPeriod = 0 .PreserveColumnInfo = True .Refresh BackgroundQuery:=False End With qtbData.Refresh 4.4 使用Microsoft Outlook对象 可以以三种方式使用Outlook的对象模型:
● 编写在本地工程文件或与Outlook本地安装相关联的COM加载项中运行的VBA代码。 ● 使用Outlook窗体中自带的脚本环境,该窗体用于显示诸如消息和约会这样的项目。 ● 通过Automation在其它Office应用程序或支持VBA的其它应用程序中使用Outlook。 本系统使用第三种方式。
在使用VBA访问Outlook对象、方法、属性之前,必须首先单击Visual Basic编辑器的Tools菜单项下的Reference来设置对Microsoft Outlook对象库的引用。 下面的示例InitializeOutlook过程创建一个新的、隐藏的Outlook实例;CreateMail过程创建一个邮件消息,设置收件人、附件、主题和消息内容,然后发送邮件。
Public golapp As Outlook.Application Public gnspNamespace As Outlook.Application Function InitializeOutlook() As Boolean This function is used to initialize the global Application On Error GoTo Init_Err Set golapp = New Outlook.Application InitializeOutlook = True Init_End: Exit Function Init_Err: InitializeOutlook = False Resume Init_End End Function Function CreateMail(astrRecip As Variant, _ strSubject As String, _ strMessage As String, _ Optional astrAttachments As Variant) As Boolean Dim objNewMail As Outlook.MailItem Dim blnResolveSuccess As Boolean On Error GoTo CreateMail_Err If golapp Is Nothing Then If InitializeOutlook = False Then MsgBox Unable to initialize Outlook Application _ & or NameSpace object variables! Exit Function End If End If Set golapp = New Outlook.Application Set objNewMail = golapp.CreateItem(olMailItem) With objNewMail .Recipients.Add astrRecip blnResolveSuccess = .Recipients.ResolveAll .Attachments.Add astrAttachments .Subject = strSubject .Body = strMessage If blnResolveSuccess Then .Send Else MsgBox Unable to resolve all recipients. Please check _ & the names. .Display End If End With CreateMail = True CreateMail_End: Exit Function CreateMail_Err: CreateMail = False Resume CreateMail_End End Fun 上一页 [1] [2] [3] [4] 下一页
|