Hi there,
I'm trying to automate copying and pasting the body of a folder of outlook items into one cell per e-mail. I've slapped together this code from other sage users:
Sub EmailText()
Dim ObjOutlook As Object
Dim MyNamespace As Object
Dim i As Integer
Dim j As Long
Dim abody() As String
Set ObjOutlook = GetObject(, "Outlook.Application")
Set MyNamespace = ObjOutlook.GetNamespace("MAPI")
For i = 1 To MyNamespace.GetDefaultFolder(6).Folders("folder").Items.Count
ThisWorkbook.Sheets(1).Cells(i, 1).Value = MyNamespace.GetDefaultFolder(6).Folders("folder").Items(i).Body
MyNamespace.GetDefaultFolder(6).Folders("folder").Items(i).Move MyNamespace.GetDefaultFolder(6).Folders("Processed")
Next
Set ObjOutlook = Nothing
Set MyNamespace = Nothing
End Sub
This works the way I want and will bring over about n e-mails and then bomb out on the nth e-mail with:
"Array index out of bounds" on line:
ThisWorkbook.Sheets(1).Cells(i, 1).Value = MyNamespace.GetDefaultFolder(6).Folders("folder").Items(i).Body
Any ideas? Why will this run for a handful of e-mails and then stop?
I feel like the answer is staring me in the face, but I can't see it. Any help is much appreciated!
Bookmarks