I have the below code that I am trying to modify to split a subject line into to six columns to view in Excel.
My data is in the below format (please note that this is subject line information only - the body of the email is not required)Sub subject2excel() On Error Resume Next Set myOlApp = Outlook.Application Set mynamespace = myOlApp.GetNamespace("mapi") Set myfolder = myOlApp.ActiveExplorer.CurrentFolder Set xlobj = CreateObject("excel.application.14") xlobj.Visible = True xlobj.Workbooks.Add 'Set Heading xlobj.Range("a" & 1).Value = "From" xlobj.Range("b" & 1).Value = "Subject" For i = 1 To myfolder.Items.Count Set myitem = myfolder.Items(i) msgtext = myitem.Body xlobj.Range("a" & i + 1).Value = myitem.Sender xlobj.Range("b" & i + 1).Value = myitem.Subject Next End Sub
SLWP Ottawa | Sales Eng. | 26-Jun-15 | Shift End: 21:00 | Leave Time: entire day | SLWP (Unpaid)
SLWP Brampton | Sales Eng. | 26-Jun-15 | Shift End: 19:00 | Leave Time: entire day | SLWP (Unpaid)
SLWP Ottawa | Sales Eng. | 26-Jun-15 | Shift End: 16:00 | Leave Time: 12:15 | SLWP (Unpaid)
I will like to have it split into the following column headers:
Column A will be - Sender
Column B will be - Location
Column C will be - LOB
Column D will be - Date
Column E will be - Shift End Time
Column F will be - Requested Leave Time
Column G will be - Paid / Unpaid
Any help will be most appreciative.
I also tried to modify the code with the below but still to no avail
Sub subject2excel() Dim myOlApp As Outlook.Application Dim myFolder As folder Dim xlobj As Object Dim i As Long Dim j As Long Dim myitem As Object Dim Words() As String 'On Error Resume Next Set myOlApp = Outlook.Application 'Set myNameSpace = myOlApp.GetNamespace("mapi") Set myFolder = myOlApp.ActiveExplorer.currentFolder Set xlobj = CreateObject("excel.application.14") xlobj.Visible = True xlobj.Workbooks.Add 'Set Heading xlobj.Range("a" & 1).Value = "From" xlobj.Range("b" & 1).Value = "Subject" For i = 1 To myFolder.Items.count Set myitem = myFolder.Items(i) If TypeOf myitem Is MailItem Then 'msgText = myitem.body xlobj.Range("a" & i + 1).Value = myitem.Sender 'xlobj.Range("b" & i + 1).Value = myitem.Subject Words = Split(myitem.Subject, " | ") For j = 0 To UBound(Words) Debug.Print Words(j) Next j End If Next i exitRoutine: Set myOlApp = Nothing Set myFolder = Nothing Set xlobj = Nothing Set myitem = Nothing End Sub




Reply With Quote