

My macro to remove “” from new message subjects is inconsistent. Result = MsgBox(MessageInfo, vbOKOnly, “New Message Received”) “Received : ” & Item.ReceivedTime & vbCrLf & _ “Sender : ” & Item.SenderEmailAddress & vbCrLf & _ ‘Set inboxItems = objectNS.GetDefaultFolder(olFolderInbox).Items It doesn’t throw any error when debugging, however it doesn’ work. Set inboxItems = objectNS.Folders(“Specification Estimation RU41”) _ Second mailbox name is “Specification Estimation RU41” I need the code to work with the second mailbox only. Outlook should execute this Modull001 by arriving a new email with the specifick subject as given above. It would be great to do not have to start this manually. I can start it manually in Outlook via Button an the Atachements are saved to the specifik folder. Public Sub SaveToDiskCancel(olMail As MailItem)ĭatei.Item(I).SaveAsFile Pfad & Datei.Item(I).FileNameĬode from Modul001 works alone fine. MsgBox Err.Number & ” – ” & Err.Description If InStr(1, outMailItem.subject, “subjectFilter”) > 0 Then If TypeName(Item) = “MailItem” And subjectFilter = (“Report: Reopen-Canceled Date “) Then Sub inboxItems_ItemAdd_Save_Attachements_RC(ByVal Item As Object) Set objectNS = outlookApp.GetNamespace(“MAPI”) I try to write VBA to save the attachements atomaticly on the disk, it new Mail come with specific Subject in the Inbox. If it works, then works, but sometime doesn’t and I really don’t know, why… Your code looks cool for me and I use it in ThisOutlookSession. Let me know in the comments section if you have any questions.įiled Under: Scripts & Utilities Tagged With: VBA Reader Interactions If you found this post helpful, I’d really appreciate it if you would rate it 😀 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.
