I need to extract emails from a secondary Outlook account into access, but it works fine on all my folders except the folder I need to extract. I've compared permissions on both secondary account folders and they are the same! I've checked the trust and unchecked the download.
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim colFolders As Outlook.Folders
Dim objFolder As Outlook.MAPIFolder
Dim objParentFolder As Outlook.MAPIFolder
Dim objMailItem As Outlook.MailItem
Dim strSQL As String
Dim strBody As String
Dim strSubject As String
Const strDoubleQuote As String = """"
Dim strFolderPath As String
Dim i As Byte
On Error GoTo Form_Load_Error
Set objApp = New Outlook.Application
Set objNS = objApp.GetNamespace("MAPI")
For i = 1 To objNS.Folders.Count
Set objParentFolder = objNS.Folders(i)
'';I use OutlookFolderNames to locate the folder in the user’s Outlook
Set objFolder = OutlookFolderNames(objParentFolder, "Inbox")
' **Note that the objFolder shows that OutlookFolderNames found the "Inbox" as valid. I can change Inbox for any other folder and it works fine**
If Not objFolder Is Nothing Then
'Once the folder is located exit For
Exit For
End If
Next i
If Not objFolder Is Nothing Then
For Each objMailItem In objFolder.Items
With objMailItem
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing
ExitProcedure:
On Error GoTo 0
Exit Sub
Form_Load_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Form_Load of VBA Document Form_frmImportEmails """
I wanted to post the function but I got a error saying there was TOO MUCH code!
question from:
https://stackoverflow.com/questions/65835410/extract-emails-from-outlook-using-access-vba-not-working-on-only-one-folder 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…