-
Help needed, exporting body mail
First of all, sorry for my bad english, I'm from Barcelona (Spain) and I took FCE many years ago.
I need help with one problem. At work, everyday, I receive more or less 100 emails with customers data, they are written following a template. The data appears in the mail body. Now, I have to fill this data in an excel file manually, I'm looking for a way to do it automatically.
I want to know two things. One, if there is any way to run a macro everytime a new mail arrives at the inbox. The second is a bit more difficult, I need to know how to export only the costumer data to a csv file.
For example, I receive something like this:
Name: Example
Telephone: 555555555
Asks for: 3000?
And I want to save a csv like "Example, 555555555, 3000?"
I've been reading this forum and others and I've tried to modify some codes but they don't work. I don't know how to refer to the body mail and to save to csv.
I wil be very grateful If anyone can help me.
Regards.
Khan.
-
Knowledge Base Approver
The King of Overkill!
VBAX Master
Hi Khan,
Give this a try, put it in your ThisOutlookSession object in Outlook. Set the location of your CSV file near the top of vInbox_ItemAdd[vba]Option Explicit
Dim WithEvents vInbox As Items
Private Sub Application_Startup()
Set vInbox = Application.Session.GetDefaultFolder(olFolderInbox).Items
Call CheckInbox
End Sub
Private Sub Application_NewMail()
If vInbox Is Nothing Then
Set vInbox = Application.Session.GetDefaultFolder(olFolderInbox).Items
Call CheckInbox
End If
End Sub
Private Sub Application_Quit()
Set vInbox = Nothing
End Sub
Function CheckInbox() As Boolean
Dim vItems As Object, vItem As Object
Set vItems = Application.Session.GetDefaultFolder(olFolderInbox).Items
For Each vItem In vItems
If TypeName(vItem) = "MailItem" Then
If vItem.UnRead = True Then
Call vInbox_ItemAdd(vItem)
End If
End If
Next
Set vItem = Nothing
Set vItems = Nothing
End Function
Private Sub vInbox_ItemAdd(ByVal Item As Object)
If TypeName(Item) <> "MailItem" Then Exit Sub
Dim RegEx As Object, vFF As Long, vFile As String, vBody As String
'Set the output CSV file location here
vFile = "C:\Customer Data.csv"
vBody = Item.Body
Set RegEx = CreateObject("vbscript.regexp")
With RegEx
.IgnoreCase = True
.Multiline = True
.Pattern = "Name
[^\n\r]*)[\n\r]*Telephone
[^\n\r]*)[\n\r]*Asks for
[^\n\r]*)"
End With
If RegEx.Test(vBody) Then
vFF = FreeFile
Open vFile For Append As #vFF
With RegEx.Execute(vBody).Item(0)
Print #vFF, Trim(.SubMatches(0)) & "," & Trim(.SubMatches(1)) & "," & _
Trim(.SubMatches(2))
End With
Close #vFF
Item.UnRead = False 'Mark As Read
End If
Set RegEx = Nothing
End Sub[/vba]
By the way, your English is fine
Matt

-
I'm going to try this on my problem (see other problems on the notice board).
I want to be able to send an email with parameters in it to my desktop whilst in a meeting with my boss (using SPV/XDA/Blakbury) to control what my computer does.
I've got several batchfiles working already, and I can make just one of these work, which forwards a PDF generated from previously saved Parameters.
If this works, I can save an email body containing the parameters and run a certain batch file to generate a PDF file from what the big boss is telling me.
Any pointers on that?
-AS
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules