1

I have searched for a solution to this, but no luck. I know it will be code based, but I'm really not sure where to start with it.

Here is the problem: Input: 1 zip file containing multiple (upwards of 50) separate "Outlook Items" Each outlook item opens up into an email that has an attachment on it. Output: 1 file with all attachments from the Outlook items inside of it.

Example: input: Myzip.zip ->

Mail_item1.msg

Mail_item2.msg

Mail_item3.msg

output: MyOutputFile ->

mail_item1_attachment.pdf

mail_item2_attachment.pdf

mail_item3_attachment.pdf

any guidance is appreciated. My only thoughts thus far are outlook VBA (can this access multiple .msg items in a folder on the C drive?)

Here is what I have so far:

Sub get_attachments_from_mailItems()
Dim inPath As String
Dim outPath As String
Dim msg As MailItem
Dim doc As Attachment

'What do I dim the following as?
Dim input_folder
Dim output_folder
Dim attachments 'collection? array?

inPath = "C:\temp\input"
outPath = "C:\temp\output"

'--I need most help with the folder objects and how to create them/use them --

'Open input folder as object
'open output folder as object

For Each msg In input_folder
    'check message for attachments, then loop if there are
    For Each doc In attachments
        'Save attachment in output_folder
    Next
Next

End Sub
user2868501
  • 91
  • 1
  • 1
  • 7
  • 1
    Yes it is possible. `1` Extract the zip to a temp folder `2` loop through the msg files `3` Open them in outlook `4` Download attachments. Give it a try and if you are stuck then post the code that you tried and we will then take it from there. – Siddharth Rout Oct 11 '13 at 13:35
  • Good to know it is possible without a batch file or something. I posted what I have done so far, I'm having trouble finding the documentation relevant to filling in the blanks – user2868501 Oct 11 '13 at 14:02
  • 1
    No if you are doing this from VBA then you don't need a batch file. `1` To open Zip file from VBA see [THIS](http://www.rondebruin.nl/win/s7/win004.htm) There are other links in the web.`2` To open msg file in outlook, see [THIS](http://msdn.microsoft.com/en-us/library/office/aa220081%28v=office.11%29.aspx) `3` To download attachments see [THIS](http://stackoverflow.com/questions/11781320/download-attachment-from-outlook-and-open-in-excel/11782153#11782153) Now you have almost every thing on the plate. Give it a try and then post back what you tried and we will then take it from there? – Siddharth Rout Oct 11 '13 at 14:13
  • Can you clarify the information in the second link that helps me open msg files from a folder on my c drive? Here is the process I'm now going for: Extract zip to "C:\temp\input". Run macro. Have attachments in "C:\temp\output" Macro: Loop through msg files in "C:\temp\input" for each msg, save attachment in "C:\temp\output" Thanks to some information you provided and some I found online, I have general direction for everything except the looping part. How could I access a folder on my c drive and loop through the unknown number of files in it? – user2868501 Oct 11 '13 at 15:15
  • Search google for `DIR` – Siddharth Rout Oct 11 '13 at 16:29
  • my new code is here: http://stackoverflow.com/questions/19383290/how-do-i-open-an-outlook-msg-file-from-my-harddrive-that-is-not-in-outlook I'm able to loop through the messages, but I can't open them. I get a run-time error that the file cant be opened when i try to use .OpenSharedItem() – user2868501 Oct 15 '13 at 14:22
  • http://www.slipstick.com/developer/remove-attachments-from-sent-messages/ ? – Mana Jan 20 '15 at 14:34

0 Answers0