Re: Saving Attachments

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Sue Mosher [MVP-Outlook] (suemvp_at_outlookcode.com)
Date: 06/28/04


Date: Mon, 28 Jun 2004 08:53:35 -0400

1) Your code below depends on an ActiveInspector window being available,
i.e. a window displaying an individual item. If you want it to work also
when you have selected an item in a folder, you need to work with
ActiveExplorer.Selection. See
http://www.outlookcode.com/codedetail.aspx?id=50 for a GetCurrentItem()
function that handles either, depending on which window is active.

2) Yes, you would need to loop through the Attachments collection to save
each Attachment as a file.

-- 
Sue Mosher, Outlook MVP
Author of
     Microsoft Outlook Programming - Jumpstart for
     Administrators, Power Users, and Developers
     http://www.outlookcode.com/jumpstart.aspx
"Andi Plotsky" <irisinfo@bellsouth.net> wrote in message
news:g6kDc.1585$pr2.574@bignews1.bellsouth.net...
>
> 1) I'm trying to save 5 attachments from 1 e-mail.  If I run it with the
> message closed, but highlighted,  I  get a "Object variable or With block
> not Set" error.   The Debugger sends me to the Set myItem line.  The code
I
> used is shown below. ( Path= C:\My Documents\test).  If I open the message
> and run it, I don't get the error, it runs through the entire routine, but
> the file hasn't really been saved.  What am I doing wrong?
>
> 2) When I'm ready to go for additional attachments do I need to loop
through
> them, or just repeat the SaveAsFile statement below with the proper index?
>
> Sub SaveAttachments()
> Dim myOlApp As Object
> Dim myItem As Outlook.MailItem
> Dim myAttachments As Attachments
>
> Set myOlApp = CreateObject("Outlook.Application")
> Set myItem = myOlApp.ActiveInspector.CurrentItem
> Set myAttachments = myItem.Attachments
> myAttachments.Item(1).SaveAsFile "C:\My Documents\test" & _
>     myAttachments.Item(1).DisplayName
> MsgBox "File Saved"
> End Sub


Relevant Pages

  • Returning selected items in an open folder
    ... items in an open folder window. ... Dim boo As Boolean ... '-- s1 is a unique string that's part of a specific open folder path. ... Private Sub Form_QueryUnload ...
    (microsoft.public.vb.general.discussion)
  • Re: Are VBA userforms always child of Windows desktop?
    ... Private Declare Function GetDesktopWindow Lib "user32" As Long ... Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long ... The system restores the window to its original state. ... Dim hWndDesktop As Long ...
    (microsoft.public.excel.programming)
  • Re: ShellExecuteEx and Information about remote application
    ... Determine when video file has been closed (when user ... Shell" and have tried to retreive the hWnd of the new video window. ... Dim ShellEI As SHELLEXECUTEINFO ... Dim hWndChild As Long ...
    (microsoft.public.vb.winapi)
  • Re: Printing File Property Information
    ... Create a new module in the upper left window if one ... Dim strPath As String ... Dim IncludeSubfolders As Boolean ... Printed' in the case of Excel or Word files. ...
    (microsoft.public.windowsxp.general)
  • Re: Why doesnt this recursive function return the right value?
    ... Simply the ByRef nHold arg works fine, though of course the function may not ... of nTmp & nResult and don't rely on the function returning a value. ... >> Dim x As Long, ... >> 'finds the first window where the class name start with ClassName ...
    (microsoft.public.excel.programming)