473,396 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

VBA with Outlook - IMAP folder access

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
3 4803
kpfunf
78
Bump .
May 19 '08 #2
Dököll
2,364 Expert 2GB
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
kpfunf
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

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

Similar topics

5
by: PIII450 | last post by:
Hi all, Does anyone know of a class which will read outlook email messages. I need to be able to scan outlook for "non-read" e-mails with a specific subject and then save the attachments and...
1
by: Fabian Müller | last post by:
Hello, I would like to access (open) my remote IMAP Mailbox with the imap_open() function in PHP Version 5.0.4. The Mailbox is located at the german provider freenet.de. The imap_open()...
14
by: Chris | last post by:
I'm trying to send an e-mail through outlook. So far I've gotten it to work with the mail script at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/149461 My only problem is that when I...
0
by: Ruud vd Velden | last post by:
Hello, We're using Office XP on Windows 2000 SP4. After installing the Oracle Connector for Outlook the following problem occurs: Emails sent by Outlook, in HTML format, do have a strange...
3
by: Kurt | last post by:
Hi We are developing an off-the-shelf software suite for a certain business sector. Most of the program is simply a GUI on top of some .mdb files. Its a .net application written in c# One...
2
by: nh_capricorn | last post by:
Hi, I am fairly new to .NET (coming from a Java background) and I am trying to port an application that I originally wrote in Java, to .NET / C#. My problem is that I cannot find a C# analog for...
4
by: lauren quantrell | last post by:
Is there a way to open the MS Outlook address book using VBA and then be able to do something with the return value? I want users to click an icon to open the Outlook address book then when an...
0
by: rcoutts | last post by:
I have a custom Access database that is a bulk mailing program for my small business to send emails to my customers (not spam!). Before sending mail, I export a folder in Outlook to an Access MDB...
1
by: CodeSeeker | last post by:
I have an application, which uses pop3 to read the messages from the mailbox, and it has been working fine for so many year. We recently have started changing this application to use java mail IMAP 4...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.