Results 1 to 4 of 4
  1. #1
    umenash is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2013
    Posts
    7

    getting outlook attachments using vba code

    i have a problom. i want my end-user to be able by pressing a button, to get access to the recent files he got to his outlook account.
    i kind of have a start but i got stuck in the end not knowing even if the beginning is good:


    Code:
    Private Sub GetAttachments()
    
    
    
    
    Dim ns As Namespace
    Dim Inbox As Outlook.MAPIFolder
    Dim folder As Outlook.MAPIFolder
    
    
    Dim Item As Object
    Dim Atmt As Attachment
    Dim FileName As String
    Dim i As Integer
    
    
    Set ns = GetNamespace("MAPI")
    Set Inbox = ns.GetDefaultFolder(olFolderInbox)
    
    
    
    
    
    
    
    
    i = 0
    
    
    If Inbox.Items.Count = 0 Then
       MsgBox "There are no messages in the Inbox.", vbInformation, _
            "Nothing Found"
       Exit Sub
    End If
    
    
      For Each Item In Inbox.Items
     For Each Atmt In Item.Attachments
    
    
             
                 FileName = "C:\" & Atmt.FileName
               
                  Attachments.SaveAsFile FileName
                  i = i + 1
          
            
                Next Atmt
               Next Item
            
    End Sub

    thanks for your help

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What do you mean by 'stuck' - error messages, wrong results, nothing happen? Have you run this procedure? Have you step debugged? Refer to link at bottom of my post for guidelines.

    The incremented i variable isn't even used for any purpose.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    umenash is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2013
    Posts
    7
    i admit i didn't understand the whole code but my aim is to show all the files in my outlook inbox- inside a folder or something and afterwards the user will be able to choose one, and i thought this code at least promotes me to there.
    in this line-
    For Each Atmt In Item.Attachments


    the error is type mismatch.
    if you can help me, i'll appreciate, it's just that all the other codes i've seen seem way to complicated then necesasary and this is the only plausible solution i have found

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Change two lines:

    Dim Atmt As Outlook.Attachment

    ...


    Atmt.SaveAsFile FileName
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Code doesn't open outlook and it should
    By mercapto in forum Programming
    Replies: 20
    Last Post: 09-21-2013, 04:03 PM
  2. Replies: 11
    Last Post: 07-24-2013, 11:49 AM
  3. Replies: 2
    Last Post: 10-24-2012, 02:09 AM
  4. Need VBA code for adding to Outlook calendar
    By geraldk in forum Programming
    Replies: 3
    Last Post: 08-24-2012, 08:38 AM
  5. Gathering data via Outlook using existing VBA code
    By Monterey_Manzer in forum Programming
    Replies: 1
    Last Post: 07-03-2012, 06:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums