此处有一例,Outlook帮助中的: 本示例在新邮件到达时显示“收件箱”文件夹。示例代码必须放在类模块中,并且在 Microsoft Outlook 调用该事件过程前必须调用 Initialize_handler 例程。Dim WithEvents myOlApp As Outlook.ApplicationSub Initialize_handler() Set myOlApp = CreateObject("Outlook.application") End SubPrivate Sub myOlApp_NewMail() Dim myExplorers As Outlook.Explorers Dim myFolder As Outlook.MAPIFolder Set myExplorers = myOlApp.Explorers Set myFolder = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox) If myExplorers.Count <> 0 Then For x = 1 To myExplorers.Count On Error GoTo skipif If myExplorers.Item(x).CurrentFolder.Name = "Inbox" Then myExplorers.Item(x).Display myExplorers.Item(x).Activate Exit Sub End If skipif: Next x End If On Error GoTo 0 myFolder.Display End Sub
先引用“Microsoft Outlook 9.0 Object Library”(你的可能不是9.0)
代码如下:
Dim OL as Outlook.Application
Set OL=CreateObject("Outlook.Application")
参数很多,但最正规
http://www.applevb.com/sourcecode/outlook1.zip
http://www.applevb.com/sourcecode/outlook_address.zip
http://www.applevb.com/sourcecode/Deleting%20mail%20with%20Outlook%20Automation.zip
本示例在新邮件到达时显示“收件箱”文件夹。示例代码必须放在类模块中,并且在 Microsoft Outlook 调用该事件过程前必须调用 Initialize_handler 例程。Dim WithEvents myOlApp As Outlook.ApplicationSub Initialize_handler()
Set myOlApp = CreateObject("Outlook.application")
End SubPrivate Sub myOlApp_NewMail()
Dim myExplorers As Outlook.Explorers
Dim myFolder As Outlook.MAPIFolder
Set myExplorers = myOlApp.Explorers
Set myFolder = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
If myExplorers.Count <> 0 Then
For x = 1 To myExplorers.Count
On Error GoTo skipif
If myExplorers.Item(x).CurrentFolder.Name = "Inbox" Then
myExplorers.Item(x).Display
myExplorers.Item(x).Activate
Exit Sub
End If
skipif:
Next x
End If
On Error GoTo 0
myFolder.Display
End Sub