Hi. I got an run-time error '02' for loop not initialized. Here are my codes and it ran through each item for a while and then stop at 'Next'. Appreciate if any one can help to check it out what the correct codes should be.
Sub ListAllContents()
Dim olApp As Outlook.Application
Dim olNamespace As Outlook.Namespace
Dim olItem As MailItem
Dim rngOut1 As Range
Dim rngOut2 As Range
Dim rngOut3 As Range
Dim rngOut4 As Range
Dim rngOut5 As Range
Sheets("Data").Select
Set olApp = New Outlook.Application
Set olNamespace = olApp.GetNamespace("MAPI")
For Each olItem In olNamespace.Folders("Mailbox - TEST").Folders("Sent Items").Folders("TEST").Items
Dim LRow As Integer
LRow = Range("A65536").End(xlUp).Row + 1
Set rngOut1 = Range("A" & LRow)
Set rngOut2 = Range("B" & LRow)
Set rngOut3 = Range("C" & LRow)
Set rngOut4 = Range("D" & LRow)
Set rngOut5 = Range("E" & LRow)
Range("A1").FormulaR1C1 = "Contents"
Range("B1").FormulaR1C1 = "From"
Range("C1").FormulaR1C1 = "Sent"
Range("D1").FormulaR1C1 = "To"
Range("E1").FormulaR1C1 = "Subject"
On Error GoTo ErrHandler:
rngOut1 = olItem.Body
Set rngOut1 = rngOut1.Offset(1, 0)
rngOut2 = olItem.SenderName
Set rngOut2 = rngOut2.Offset(1, 0)
rngOut3 = olItem.SentOn
Set rngOut3 = rngOut3.Offset(1, 0)
rngOut4 = olItem.To
Set rngOut4 = rngOut4.Offset(1, 0)
rngOut5 = olItem.Subject
Set rngOut5 = rngOut5.Offset(1, 0)
Range("C2,E2").Select
Selection.Copy
Sheets("Recap").Select
Dim LRec As Integer
LRec = Range("A65536").End(xlUp).Row + 1
Range("A" & LRec).Select
ActiveSheet.Paste
Sheets("Data").Select
Call Convert
ErrHandler:
Next
Sheets("Edit Final").Select
Thanks!
Sub ListAllContents()
Dim olApp As Outlook.Application
Dim olNamespace As Outlook.Namespace
Dim olItem As MailItem
Dim rngOut1 As Range
Dim rngOut2 As Range
Dim rngOut3 As Range
Dim rngOut4 As Range
Dim rngOut5 As Range
Sheets("Data").Select
Set olApp = New Outlook.Application
Set olNamespace = olApp.GetNamespace("MAPI")
For Each olItem In olNamespace.Folders("Mailbox - TEST").Folders("Sent Items").Folders("TEST").Items
Dim LRow As Integer
LRow = Range("A65536").End(xlUp).Row + 1
Set rngOut1 = Range("A" & LRow)
Set rngOut2 = Range("B" & LRow)
Set rngOut3 = Range("C" & LRow)
Set rngOut4 = Range("D" & LRow)
Set rngOut5 = Range("E" & LRow)
Range("A1").FormulaR1C1 = "Contents"
Range("B1").FormulaR1C1 = "From"
Range("C1").FormulaR1C1 = "Sent"
Range("D1").FormulaR1C1 = "To"
Range("E1").FormulaR1C1 = "Subject"
On Error GoTo ErrHandler:
rngOut1 = olItem.Body
Set rngOut1 = rngOut1.Offset(1, 0)
rngOut2 = olItem.SenderName
Set rngOut2 = rngOut2.Offset(1, 0)
rngOut3 = olItem.SentOn
Set rngOut3 = rngOut3.Offset(1, 0)
rngOut4 = olItem.To
Set rngOut4 = rngOut4.Offset(1, 0)
rngOut5 = olItem.Subject
Set rngOut5 = rngOut5.Offset(1, 0)
Range("C2,E2").Select
Selection.Copy
Sheets("Recap").Select
Dim LRec As Integer
LRec = Range("A65536").End(xlUp).Row + 1
Range("A" & LRec).Select
ActiveSheet.Paste
Sheets("Data").Select
Call Convert
ErrHandler:
Next
Sheets("Edit Final").Select
Thanks!