So, firstly, I am a newbie of VB working from scratch, but in the past I edited some code. The closest question I could find was this , but that was not quite the way I had hoped.
So, I use Outlook / Excel 2007, and I get a daily email containing some data in a fixed form. What I hope to do is set up a macro / Script that will search in my Outlook inbox, and then, based on the correct message object, it will look in the message body and extract certain parts into the Excel worksheet.
I think VB is probably the best way to do this based on my knowledge, but I'm not quite sure where to start. Any help on the overall code structure or other similar examples would be greatly appreciated. I just want to start and, hopefully, figure out future exercises on my own. Thanks!
So thanks for the help! Basically, I got this work, I just couldn’t automatically update it when I receive a new message. I have a rule configured that moves the corresponding emails to their own folder, and I was able to configure an open macro that I can run, which pulls out all the data (for each letter) and uploads them to a CSV file.
I tried to adapt this macro in the example that you specified above, which should automatically start when I receive a new message, but have not succeeded so far. Password analysis should not change (and it definitely works in the start macro manually), so this is normal, it just runs the auto-update macro for a new message. Am I missing something? Here is what I have, which basically matches the example above, except for the new folder (and is a module of the class):
Public WithEvents myOlItems As Outlook.Items Public Sub Application_Startup() ' Reference the items in the Inbox. Because myOlItems is declared ' "WithEvents" the ItemAdd event will fire below. Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Folders("FolderX").Items End Sub Private Sub myOlItems_ItemAdd(ByVal Item As Object) Dim objOutlook As New Outlook.Application Dim objNameSpace As Outlook.NameSpace Dim objFolder As Outlook.MAPIFolder Dim objMail As MailItem Dim count As Integer Dim myTitlePos As Integer Dim myTitleLen As Integer Dim myVarPos As Integer Dim myVarLen As Integer Dim strPrice As String Dim strYear As String Dim myVarCRLF As Integer Dim myDate As Date Dim newLineTest As String ' Check to make sure it is an Outlook mail message, otherwise ' subsequent code will probably fail depending on what type ' of item it is. If TypeName(Item) = "MailItem" Then ' Data processing and parsing is done here End Sub