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

    downloading an attachment from outlook via vba access


    it doe'snt matter which directory i write, it debugs me that i have no permission to that dir.
    Code:
        Dim myOlApp As Outlook.Application    Dim myInspector As Outlook.Inspector
        Dim myItem As Outlook.MailItem
        Dim myAttachments As Outlook.Attachments
        Set myOlApp = CreateObject("Outlook.Application")
        Set myInspector = myOlApp.ActiveInspector
        If Not TypeName(myInspector) = "Nothing" Then
            If TypeName(myInspector.CurrentItem) = "MailItem" Then
                Set myItem = myInspector.CurrentItem
                Set myAttachments = myItem.Attachments
                'Prompt the user for confirmation
                Dim strPrompt As String
                strPrompt = "Are you sure you want to save the first attachment in the current item to the C:\ folder? If a file with the same name already exists in the destination folder, it will be overwritten with this copy of the file."
                If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
                    myAttachments.Item(1).SaveAsFile "C:\" & _
                    myAttachments.Item(1).DisplayName
                End If
            Else
                MsgBox "The item is of the wrong type."
            End If

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Is it the path you are writing to or the path you are copying from that is giving you permision issues? Seems like you are trying to copy from a system folder/file.

  3. #3
    umenash is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2013
    Posts
    7
    this is the path i want the attached file will be downloaded to. and even when i wrote desktop ar whatever it always shows the same error

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    I understand you want to paste a copy to the path of your choosing. From your description, it seems the error is related to a permissions issue. Do you have permission to copy the file/attachment? I would guess you should have permission to copy. I am just going off of what you have stated here.

  5. #5
    umenash is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2013
    Posts
    7
    well, i tried with a different code and it downloaded the files with no problem, but i didn;t use it because it had other errors. about the permission, i don't understand what it means no permission. if i do that manually, i can do anythung with this file. so why would i have a permission problem automatically?

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by umenash View Post
    so why would i have a permission problem automatically?
    Correct, it does not add up. I was simply going off of what you stated in your post.

    I tested the code. I used an XP machine and referenced a couple items like Offfice Outlook, etc. It worked for me. I hard coded a "Test" folder in my C: drive. I added an "End If". It worked without a hitch, the first time. Are you getting the prompt to save the file? the one that asks "Are you sure you want to save the first attachment........"

    Code:
    Private Sub cmdExecute_Click()
    
    Dim myOlApp As Outlook.Application
    Dim myInspector As Outlook.Inspector
    Dim myItem As Outlook.MailItem
    Dim myAttachments As Outlook.Attachments
        Set myOlApp = CreateObject("Outlook.Application")
        Set myInspector = myOlApp.ActiveInspector
     
    
            If Not TypeName(myInspector) = "Nothing" Then
            
                If TypeName(myInspector.CurrentItem) = "MailItem" Then
                    Set myItem = myInspector.CurrentItem
                    Set myAttachments = myItem.Attachments
                    'Prompt the user for confirmation
                    Dim strPrompt As String
                    strPrompt = "Are you sure you want to save the first attachment in the current item to the C:\ folder? If a file with the same name already exists in the destination folder, it will be overwritten with this copy of the file."
                        
                        If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
                            myAttachments.Item(1).SaveAsFile "C:\Test\" & _
                            myAttachments.Item(1).DisplayName
                        End If
                Else
                    MsgBox "The item is of the wrong type."
                End If
                
            End If
    
    End Sub

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

Similar Threads

  1. Replies: 1
    Last Post: 04-01-2013, 05:00 PM
  2. Send email in Outlook with attachment
    By kelkan in forum Programming
    Replies: 1
    Last Post: 02-01-2013, 10:31 PM
  3. Excel attachment and save as draft in outlook
    By ragsgold in forum Programming
    Replies: 1
    Last Post: 02-01-2013, 05:55 PM
  4. Issue downloading the actual data from an Access database,
    By LNDSS in forum Import/Export Data
    Replies: 1
    Last Post: 02-24-2012, 04:12 PM
  5. Downloading a File using VBA
    By graviz in forum Programming
    Replies: 1
    Last Post: 03-15-2010, 04:49 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