Solved

Need to get all the details in the mail to an excel with a macro in row wise

Posted on 2007-11-20
13
227 Views
Last Modified: 2010-04-21
Hi,

I send a mail to a vendor.for any printer problems that i have.Now as the mails have reched 100's it becomes difficult to see all.
I have the mail content like this.
=========================
Hi ,
                   
                   The  below  mentioned   printer  having the problem .The printout is coming with black patches .So please do the needful   as soon as possible..

Details:

printer model                --  Kyocera FS-3800            
printer s.no                   --  AFT44007867419            
customer name            --  (SB-3F)        
problem type                --  Black Pages
contact person name   -- SHarath.
contact number            -- 3073186349345234

Regards,
Sharath
=================================

So need all data to row wise in a excel sheet.

Any help...

Regards
Sharath
0
Comment
Question by:bsharath
  • 9
  • 4
13 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 20319647
Hi, bsharath.

That's easy enough to do if those lines are consistent (that is, if the always have the same format).  Do they?
0
 
LVL 11

Author Comment

by:bsharath
ID: 20319817
This content is going to be same

printer model                --  Kyocera FS-3800            
printer s.no                   --  AFT44007867419            
customer name            --  (SB-3F)        
problem type                --  Black Pages
contact person name   -- SHarath.
contact number            -- 3073186349345234

Some time some extra fields...
If the mail has extra fields then create a new sheet and place them there...Or put it in the same sheet so that i can sort them later
0
 
LVL 11

Author Comment

by:bsharath
ID: 20348390
Any help...
0
 
LVL 76

Expert Comment

by:David Lee
ID: 20355449
Sorry to be so slow.  This should do it.  Select as many messages as you want, so long as they all match the pattern you gave, and run the macro.  It'll process all of them and put them into an Excel spreadsheet, one row per message.




Sub ParseMessage()

    Dim olkMessage As Outlook.MailItem, _

        arrLines As Variant, _

        varLine As Variant, _

        arrLine As Variant, _

        varKey As Variant, _

        excApp As Object, _

        excBook As Object, _

        excSheet As Object, _

        intIndex As Integer

    Set excApp = CreateObject("Excel.Application")

    Set excBook = excApp.Workbooks.Add()

    Set excSheet = excBook.Sheets(1)

    intIndex = 1

    For Each olkMessage In Application.ActiveExplorer.Selection

        arrLines = Split(olkMessage.Body, vbCrLf)

        For Each varLine In arrLines

            arrLine = Split(varLine, "--")

            If UBound(arrLine) = 1 Then

                varKey = Replace(arrLine(0), Chr(160), "")

                varKey = Trim(varKey)

                Select Case varKey

                    Case "printer model"

                        excSheet.Cells(intIndex, 1) = arrLine(1)

                    Case "printer s.no"

                        excSheet.Cells(intIndex, 2) = arrLine(1)

                    Case "customer name"

                        excSheet.Cells(intIndex, 3) = arrLine(1)

                    Case "problem type"

                        excSheet.Cells(intIndex, 4) = arrLine(1)

                    Case "contact person name"

                        excSheet.Cells(intIndex, 5) = arrLine(1)

                    Case "contact number"

                        excSheet.Cells(intIndex, 6) = Chr(34) & arrLine(1) & Chr(34)

                End Select

            End If

        Next

        intIndex = intIndex + 1

    Next

    'Change the path/filename on the following line as needed

    excBook.SaveAs "C:\eeTesting\BSharath.xls"

    excBook.Close

    Set excSheet = Nothing

    Set excBook = Nothing

    Set excApp = Nothing

    Set olkMessage = Nothing

End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 20355487
Thanks a lot Can i get the headers also.
Is it possible to find which is left out on the selected mails if any.In sheet 2.Because of header mismatch.
0
 
LVL 11

Author Comment

by:bsharath
ID: 20355519
Sorry for another addition.I need to get the Mail sent date also to the excel.Only then the whole file is ready.
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 11

Author Comment

by:bsharath
ID: 20379910
A little more help please...
0
 
LVL 76

Expert Comment

by:David Lee
ID: 20384091
Where do you want the date to go, the begining, the end, somewhere in the middle?
0
 
LVL 11

Author Comment

by:bsharath
ID: 20387222
The begining....
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 20400275
Try this.
Sub ParseMessage()

    Dim olkMessage As Outlook.MailItem, _

        arrLines As Variant, _

        varLine As Variant, _

        arrLine As Variant, _

        varKey As Variant, _

        excApp As Object, _

        excBook As Object, _

        excSheet As Object, _

        intIndex As Integer

    Set excApp = CreateObject("Excel.Application")

    Set excBook = excApp.Workbooks.Add()

    Set excSheet = excBook.Sheets(1)

    intIndex = 1

    For Each olkMessage In Application.ActiveExplorer.Selection

        excSheet.Cells(intIndex, 1) = olkMessage.ReceivedTime

        arrLines = Split(olkMessage.Body, vbCrLf)

        For Each varLine In arrLines

            arrLine = Split(varLine, "--")

            If UBound(arrLine) = 1 Then

                varKey = Replace(arrLine(0), Chr(160), "")

                varKey = Trim(varKey)

                Select Case varKey

                    Case "printer model"

                        excSheet.Cells(intIndex, 2) = arrLine(1)

                    Case "printer s.no"

                        excSheet.Cells(intIndex, 3) = arrLine(1)

                    Case "customer name"

                        excSheet.Cells(intIndex, 4) = arrLine(1)

                    Case "problem type"

                        excSheet.Cells(intIndex, 5) = arrLine(1)

                    Case "contact person name"

                        excSheet.Cells(intIndex, 6) = arrLine(1)

                    Case "contact number"

                        excSheet.Cells(intIndex, 7) = Chr(34) & arrLine(1) & Chr(34)

                End Select

            End If

        Next

        intIndex = intIndex + 1

    Next

    'Change the path/filename on the following line as needed

    excBook.SaveAs "C:\eeTesting\BSharath.xls"

    excBook.Close

    Set excSheet = Nothing

    Set excBook = Nothing

    Set excApp = Nothing

    Set olkMessage = Nothing

End Sub

Open in new window

0
 
LVL 11

Author Closing Comment

by:bsharath
ID: 31410093
Thanks a lot....For this excellent help....
0
 
LVL 11

Author Comment

by:bsharath
ID: 21093142
0
 
LVL 11

Author Comment

by:bsharath
ID: 21093146
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Outlook 2016 and Surface Pro 4 9 38
Outlook 2010 not opening hyperlinks 6 19
Dynamic Filter ? 4 20
excel help 4 18
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now