By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,350 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

VBA with Outlook - IMAP folder access

P: 78
I have the following code that works in accessing my personal folder inbox and subfolders.
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Sub SaveAttachmentsToFolder()
  3. On Error GoTo SaveAttachmentsToFolder_err
  4. ' Declare variables
  5. Dim ns As NameSpace
  6. Dim Inbox As MAPIFolder
  7. Dim SubFolder As MAPIFolder
  8. Dim SubSubFolder As MAPIFolder
  9. Dim Item As Object
  10. Dim Atmt As Attachment
  11. Dim FileName As String
  12. Dim i As Integer
  13. Dim varResponse As VbMsgBoxResult
  14. Set ns = GetNamespace("MAPI")
  15. Set Inbox = ns.GetDefaultFolder(olFolderInbox)
  16. Set SubFolder = Inbox.Folders("Fuel").Folders("Apache")
  17. i = 0
  18. If SubFolder.Items.Count = 0 Then
  19. MsgBox "There are no messages in the Sales Reports folder.", vbInformation, _
  20. "Nothing Found"
  21. Exit Sub
  22. End If
  23. For Each Item In SubFolder.Items
  24. For Each Atmt In Item.Attachments
  25. If Right(Atmt.FileName, 3) = "pdf" Then
  26. FileName = "P:\Fuel\Fuel Records 2008\Apache\" & Atmt.FileName
  27. Atmt.SaveAsFile FileName
  28. i = i + 1
  29. End If
  30. Next Atmt
  31. Next Item
  32. If i > 0 Then
  33. varResponse = MsgBox("I found " & i & " attached files." _
  34. & vbCrLf & "I have saved them into the Outlook Attachment Test folder." _
  35. , vbInformation, "Finished!")
  36. ' Open Windows Explorer to display saved files if user chooses
  37. If varResponse = vbYes Then
  38. Shell "Explorer.exe /e,P:\Fuel\Fuel Records 2008\Apache\", vbNormalFocus
  39. End If
  40. Else
  41. MsgBox "I didn't find any attached files in your mail.", vbInformation, "Finished!"
  42. End If
  43. ' Clear memory
  44. SaveAttachmentsToFolder_exit:
  45. Set Atmt = Nothing
  46. Set Item = Nothing
  47. Set ns = Nothing
  48. Exit Sub
  49. ' Handle Errors
  50. SaveAttachmentsToFolder_err:
  51. MsgBox "An unexpected error has occurred." _
  52. & vbCrLf & "Please note and report the following information." _
  53. & vbCrLf & "Macro Name: GetAttachments" _
  54. & vbCrLf & "Error Number: " & Err.Number _
  55. & vbCrLf & "Error Description: " & Err.Description _
  56. , vbCritical, "Error!"
  57. Resume SaveAttachmentsToFolder_exit
  58. End Sub
  59.  
This works well, but is for the personal folder. I have now moved all fuel folders to an IMAP account called "Fuel", which has an Inbox, then subfolders. How do I access this account rather than my personal folder? I don't know how else to use GetDefaultFolder. Thanks.
May 16 '08 #1
Share this Question
Share on Google+
3 Replies


P: 78
Bump .
May 19 '08 #2

Dököll
Expert 100+
P: 2,364
Bump .
Hey there kpfunf! I believe to ahve added thi for you in the VBA forum, did it not work? Please let us know how further we can help.

In a bit!

Dököll
May 20 '08 #3

P: 78
Dokoll,
I'm not sure what you're referring to. I search for IMAP and didn't find another thread.
May 20 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.