Surveillance outlook (2) vb wry mouth ares

The following code shows an email in Outlook. The effect is equivalent to double-clicking the email to open it

The premise is to quote some things:
Project->Reference->Select Mircrosoft outlook 15.0 object library and Microsoft Outlook view control->Click OK


Private Sub Form_Load()

    MsgBox (Environ("username"))
    MsgBox (Environ("computername"))
    
    DisplayFirstItem
        
End Sub


Sub DisplayFirstItem()
 
 Dim myNameSpace As Outlook.NameSpace
 
 Dim myFolder As Outlook.Folder
 
 Set myNameSpace = Application.GetNamespace("MAPI")
 
 Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
 
 On Error GoTo ErrorHandler
 
 myFolder.Items(1).Display
 
 Exit Sub
 
ErrorHandler:
 
 MsgBox "There are no items to display."
 
End Sub

''https://docs.microsoft.com/zh-cn/office/vba/api/Outlook.MailItem.Display

It doesn't even need the user to have already opened Outlook!

Guess you like

Origin blog.csdn.net/wangduqiang747/article/details/108472941