viewpoint-particle

Author Topic: Saving Outlook attachments from a folder other than inbox  (Read 86 times)

pauls681

  • Newbie
  • *
  • Posts: 5
Saving Outlook attachments from a folder other than inbox
« on: April 01, 2021, 06:44:07 am »
I have the following code to copy attachments out of email in the inbox and it works.
What I want to do is copy attachments out of another folder.
How and where do i specify that outlook folder?
Any help is greatly appreciated.

AddExtender("wwfaf44i.dll")
olFolderInbox=6
SaveTo = "C:\docstoprint\"
MSapp = ObjectCreate ("Outlook.Application")
oNameSpace = MSapp.GetNamespace("MAPI")
oFolder = oNameSpace.GetDefaultFolder(olFolderInbox)
oFolderItems=oFolder.Items
msgcount = oFolderItems.count
For a = 1 to msgcount
   oMessage = oFolderItems.Item(a)
   oAttachments = oMessage.Attachments
   attachcount = oAttachments.Count
   For b = 1 to attachcount
      oAttachItem = oAttachments.Item(b)
      fname = oAttachItem.filename
      filetosave = StrCat(SaveTo,fname)
      oAttachItem.SaveAsFile(filetosave)
      oAttachItem = 0
   Next
   oAttachments = 0
   oMessage = 0
Next



oFolderItems = 0
oFolder = 0
oNameSpace = 0
MSapp = 0

td

  • Tech Support
  • *****
  • Posts: 3707
    • WinBatch
Re: Saving Outlook attachments from a folder other than inbox
« Reply #1 on: April 01, 2021, 09:47:38 am »
Not sure why you loading the FAF extender when the script you posted doesn't use it but maybe it is a snippet from a larger script.

If you are lucky your folder is one of the default folders listed in the OLDefaultFolders enumeration. You can find the complete list using the WIL Type Viewer or performing a quick Web search on the term "OLDefaultFolders".  If you find it there, you just need to use the enumeration's value as the parameter to the "GetDefaultFolder" method. If you are not lucky you will likely have to use the "GetFolderFromID" or something similar but I am not sure how to go about determining the entryID or the storeID of an email message or a folder.

Perhaps someone more familiar with the Outlook object model can provide additional assistance.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

  • Tech Support
  • *****
  • Posts: 3707
    • WinBatch
Re: Saving Outlook attachments from a folder other than inbox
« Reply #2 on: April 01, 2021, 09:56:44 am »
Happened to notice that the Outlook Namespace object has a "Folders" property that returns a collection of folder objects.  With a little trial and error and an examination of the object model you should be able to sort it out.

Here is a Tech DB example that enumerates sub folders it may be of some help.

https://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP/OLE~and~Outlook+List~Subfolders.txt

There may be other examples in the Tech DB that are useful so it is worth a search.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

pauls681

  • Newbie
  • *
  • Posts: 5
Re: Saving Outlook attachments from a folder other than inbox
« Reply #3 on: April 01, 2021, 10:26:46 am »
Thank you, I will investigate more and report back when I get this working.
On the faf extender... You are correct that there is more code doing some file manipulation that the faf extender is needed for.
Thank you so much for your help.

pauls681

  • Newbie
  • *
  • Posts: 5
Re: Saving Outlook attachments from a folder other than inbox
« Reply #4 on: April 01, 2021, 10:42:05 am »
Got it!
oFolder = oNameSpace.GetDefaultFolder(olFolderInbox).Folders("Invoice")
Invoice is a sub folder under inbox, before it was not. This should work great for what I'm doing.
Thank you for your help!