goss
10-08-2011, 02:46 PM
Hi All,
Using Outlook 2010.
I would like to loop through a folder in .pst and save each mailitem as a text file.
When I run my code, I receive this error message:
Run-time error "-2147221233 (8004010f)':
The attempted opderation failed. An Object could not be found.
Debug points here
Set olFolderPayments = olNS.Folders("pst-goss\payments") '<- \\ Removed
The path and folder definitely exist.
I ran some code to print the folder name and path tro the immediate window and that worked great so I am not sure what I'm doing wrong?
Edit: The paths in the code below are correct. I was forced to remove them before I could post
Thanks,
goss
Full code:
Option Explicit
Sub SavePmntsAsTxt()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Author: Unknown (MSDN)
'Date Extracted: 10/08/2011
'Link: (Removed)
'&
'Link: (Removed)
'Modified by: goss
'Modified Date: 10/08/2011
'References: Microsoft Scripting Runtime
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim olApp As Application
Dim olNS As NameSpace
Dim olFolderPayments As MAPIFolder
Dim item As Object
Dim strReports As String
Dim strFile As String
Dim strBody As String
Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI") ' open the MAPI Namespace
Set olFolderPayments = olNS.Folders("") '<-Removed
strReports = "C:\Payments\"
With olFolderPayments
For Each item In .Items
strBody = item.Body
strFile = strReports & "Payment_" & Format(item.ReceivedTime, "yyyymmdd_hhmmss") & ".txt"
Open strFile For Output As #1
Print #1, strBody
Close #1
Next item
End With
'Tidy up
Set olApp = Nothing
Set olNS = Nothing
Set olFolderPayments = Nothing
Set olFolderxPayments = Nothing
Set item = Nothing
End Sub
Using Outlook 2010.
I would like to loop through a folder in .pst and save each mailitem as a text file.
When I run my code, I receive this error message:
Run-time error "-2147221233 (8004010f)':
The attempted opderation failed. An Object could not be found.
Debug points here
Set olFolderPayments = olNS.Folders("pst-goss\payments") '<- \\ Removed
The path and folder definitely exist.
I ran some code to print the folder name and path tro the immediate window and that worked great so I am not sure what I'm doing wrong?
Edit: The paths in the code below are correct. I was forced to remove them before I could post
Thanks,
goss
Full code:
Option Explicit
Sub SavePmntsAsTxt()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Author: Unknown (MSDN)
'Date Extracted: 10/08/2011
'Link: (Removed)
'&
'Link: (Removed)
'Modified by: goss
'Modified Date: 10/08/2011
'References: Microsoft Scripting Runtime
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim olApp As Application
Dim olNS As NameSpace
Dim olFolderPayments As MAPIFolder
Dim item As Object
Dim strReports As String
Dim strFile As String
Dim strBody As String
Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI") ' open the MAPI Namespace
Set olFolderPayments = olNS.Folders("") '<-Removed
strReports = "C:\Payments\"
With olFolderPayments
For Each item In .Items
strBody = item.Body
strFile = strReports & "Payment_" & Format(item.ReceivedTime, "yyyymmdd_hhmmss") & ".txt"
Open strFile For Output As #1
Print #1, strBody
Close #1
Next item
End With
'Tidy up
Set olApp = Nothing
Set olNS = Nothing
Set olFolderPayments = Nothing
Set olFolderxPayments = Nothing
Set item = Nothing
End Sub