Downloading Attachments using Macro

Alexk13

New Member
Joined
Sep 18, 2020
Messages
6
Office Version
  1. 2010
Platform
  1. Windows
Hi all,
I have a macro which downloads attachments based on a given Download Path (F1), Date Range (F2 & F3), Attachment extension/ type (F5), Main Folder Name (F6) and Sub-folder name (F7).
I want to be able to download attachments in a specific folder in my mailbox but it doesn't work when I simply want to download attachments in "Inbox" it only works if I want to download attachments in my Sub-folders. for example assuming the following is my mailbox structure:

[IMG alt="Name: Screenshot1.png
Views: 17
Size: 2.8 KB"]Excel Help Forum

If I use this code to download attachments in my Inbox, where F6 value is My mailbox name and F7 is set to "Inbox" it give me type miss match error.
VBA Code:
Set Folder = Outlook.GetNamespace("MAPI").Folders(Sheet.Range("F6").Value).Folders(Sheet.Range("F7").Value)


but if I change it to this, it gets me the right attachments in the Read Later subfolder.
Code:
Set Folder = Outlook.GetNamespace("MAPI").Folders(Sheet.Range("F6").Value).Folders(Sheet.Range("F6").Value).Folders(Sheet.Range("F7").Folders("Read Later")

Why is the first case failing and how to fix it?
Thanks,
Alex
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi all,
I have a macro which downloads attachments based on a given Download Path (F1), Date Range (F2 & F3), Attachment extension/ type (F5), Main Folder Name (F6) and Sub-folder name (F7).
I want to be able to download attachments in a specific folder in my mailbox but it doesn't work when I simply want to download attachments in "Inbox" it only works if I want to download attachments in my Sub-folders. for example assuming the following is my mailbox structure:

Screenshot1.png


If I use this code to download attachments in my Inbox, where F6 value is My mailbox name and F7 is set to "Inbox" it give me type miss match error.
VBA Code:
Set Folder = Outlook.GetNamespace("MAPI").Folders(Sheet.Range("F6").Value).Folders(Sheet.Range("F7").Value)


but if I change it to this, it gets me the right attachments in the Read Later subfolder.
Code:
Set Folder = Outlook.GetNamespace("MAPI").Folders(Sheet.Range("F6").Value).Folders(Sheet.Range("F6").Value).Folders(Sheet.Range("F7").Folders("Read Later")

Why is the first case failing and how to fix it?
Thanks,
Alex
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Downloading Attachments using Macro
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
I did Ask this in ExcelForum.com but nobody has been able to help yet. Here is the link:
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top