![]() It’s worth taking a look at all of the available properties of the Outlook mailitem that are available. I used it to insert rows into a SQL table, then move the message to a different folder. You can of course do whatever you like with the message when it is received. The above code will produce a simple message box that shows some of the message properties: You need to restart Outlook for the code to become active. MsgBox Err.Number & " - " & Err.Description Result = MsgBox(MessageInfo, vbOKOnly, "New Message Received") "Received : " & Item.ReceivedTime & vbCrLf & _ "Sender : " & Item.SenderEmailAddress & vbCrLf & _ Private Sub inboxItems_ItemAdd(ByVal Item As Object) ![]() Set inboxItems = objectNS.GetDefaultFolder(olFolderInbox).Items Set objectNS = outlookApp.GetNamespace("MAPI") Private WithEvents inboxItems As Outlook.Items ![]() ![]() A the following code to ThisOutlookSession: Option Explicit You need to add an event listener to the Inbox which will process incoming messages. It’s easy to do but can take a bit of trial and error to get working just how you want it. A customer asked me to write something that would log an entry to a SQL database when an email produced contact form was received. It can be very useful to run a VBA macro when new mail is received in Outlook.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |