0

I regularly receive emails that have 30+ attached emails with PDF files nested inside. I need a VBA code that will copy ALL of the nested PDF files to a folder outside Outlook. Could some one kindly point me in the right direction.

Example:

Main Email
   Attached email
      PDF attachment
   Attached email
      PDF attachment
   Attached email
      PDF attachment
   Attached email
      PDF attachment
   Etc...

How do I copy all the nested PDF's to a folder outside outlook in one action?

Thank you in advance for the direction.

Ken White
  • 123,280
  • 14
  • 225
  • 444
Mark
  • 1
  • Sorry the format of the question did not display as intended. – Mark Mar 27 '19 at 21:44
  • How do you type a basic question without the formatting getting altered? Stackoverflow keeps thinking my example is code. It is not. Anyway. Hopefully my initial question is understood. – Mark Mar 27 '19 at 21:47
  • Welcome to SO! This site uses [Markdown](https://stackoverflow.com/editing-help) for formatting. A uniform 4-space indent is used to mark a line as a block of code. Did you mean to make a bullet list? In any case, it looks like your question as it stands is *too broad* to be reasonably answerable, and will probably end up being put on hold. Rule of thumb, "I need code that does XYZ" isn't going to work. Do you code that can add an attachment and you need help iterating PDF files? See the "related" posts in the side bar to get you started. – Mathieu Guindon Mar 27 '19 at 21:52
  • [This](https://stackoverflow.com/q/14245712/1188513) might also help. – Mathieu Guindon Mar 27 '19 at 21:52
  • There is help available for formatting when you're typing your post, in the form of a *?* button on the editor toolbar. – Ken White Mar 27 '19 at 23:36

1 Answers1

0

Outlook does not let you access embedded message attachments directly - you would need to save them first using Attachment.SaveAsFile, and then open the MSG file using Namespace.OpenSharedItem.

If using Redemption is an option (I am its author), it exposes the RDOAttachment.EmbeddedMsg property that returns the embedded message attachment as an RDOMail object:

set OutlookMsg = Application.ActiveExplorer.Selection(1)

set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set msg = Session.GetRDOObjectFromOutlookObject(OutlookMsg)
ProcessMessage(msg)

sub ProcessMessage(msg)
  for each attach in msg.Attachments
    if attach.Type = olEmbeddedItem Then
      ProcessMessage(attach.EmbeddedMsg)
    elseif attach.Type = olByValue Then
      attach.SaveAsFile "c:\temp\" & attach.FileName
    End If
  next
end sub
Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • My organization does not use Redemption so this will not be an option. Are there any other solutions or sample VBA code I could use to solve this? Somehow I need to "move" or "save-as" many pdfs that are buried in nested Outlook email attachments. – Mark May 28 '19 at 21:54
  • It is either Extended MAPI (C++ or Delphi only) or Redemption (any language). Otherwise it is only recursively saving the embedded message attachments as MSG files (Attachment.SaveAsFile) and then opening it using Namespace.OpenSharedItem – Dmitry Streblechenko May 28 '19 at 22:28