Announcement

Collapse
No announcement yet.

Save Attachments From Outlook

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Save Attachments From Outlook



    Hi all,

    Not sure if this can be done, I would like to collate excel email attachments from an outlook inbox. If possible I would like to save the files into a folder on a local drive. I would then like to log in a master document details within each attachment which will alwalys be held in the same cell location.

    To add complication, not sure if this can be done, but would like to also save the attachment using all data from the FROM email address up until the '@' part then use a cell i.e. B5 inside the attachment itself as the rest of the filename.

    Some emails will have multiple attachments so not sure if VBA can save each attachment in the way I described above.

    Hope someone can help or at least get me started in the right place.

    Thanks for any help
    Pylorus

  • #2
    Re: Save Attachments From Outlook

    This might get you started.

    Sub SaveAttachments()
    Dim myOlapp As Outlook.Application
    Dim myNameSpace As Outlook.NameSpace
    Dim myFolder As Outlook.MAPIFolder
    Dim myItem As Outlook.MailItem
    Dim myAttachment As Outlook.Attachment
    Dim I As Long

    Set myOlapp = CreateObject("Outlook.Application")
    Set myNameSpace = myOlapp.GetNamespace("MAPI")
    Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
    Set myFolder = myFolder.Folders("Job Stuff")

    For Each myItem In myFolder.Items
    If myItem.Attachments.Count <> 0 Then
    For Each myAttachment In myItem.Attachments
    I = I + 1
    myAttachment.SaveAsFile "C:\MailTest\Attachment" & I & ".csv"
    Next
    End If

    Next
    End Sub
    Boo!

    Comment


    • #3
      Re: Save Attachments From Outlook

      Thanks Norie, this is really great, but how would I adapt this code to look at a subfolder?

      Also any views about the second part of my email, i.e. saving the attachments with specific file names?

      Thanks for your help
      Pylorus

      Comment


      • #4
        Re: Save Attachments From Outlook

        What do you mean by look at a subfolder?

        A subfolder in Outlook or on your C: drive?
        Boo!

        Comment


        • #5
          Re: Save Attachments From Outlook

          I meant an outlook subfolder, is just simply change to the name of inbox to the subfolder name, or do I need to change other parts of the code?

          Comment


          • #6
            Re: Save Attachments From Outlook

            The code I posted does use an Outlook subfolder - 'Job Stuff'.
            Boo!

            Comment


            • #7
              Re: Save Attachments From Outlook

              O.k. thanks Norie, it all makes sense now, really useful code, I think once the files have been saved, I can use excel vba to check and save the documents as specific file types, and even create a log file.

              Thanks again for your help.

              Pylorus

              Comment


              • #8
                Re: Save Attachments From Outlook

                Hi,

                I am faced with a similar scenario, needing to download attachments from emails within an outlook folder. I used the above code but I'm getting the error "Compile Error: User-defined type not defined" on the first line "dim myOlapp as outlook.application".

                Can anyone help me resolve this issue?

                Thanks

                Comment


                • #9
                  Re: Save Attachments From Outlook

                  You've been a member for some time Steven so it would probably be a good time to remind yourself of the rules here... http://www.ozgrid.com/forum/announcement.php?f=8

                  Rule #8 specifically prohibits posting a question in another members' thread. This is to keep threads 'on-topic' according to the title. Other questions tend to make the thread veer away from the original question. Even though your problem is similar, the rule still applies.

                  In any case, you have already posted a very similar question at http://www.ozgrid.com/forum/showthre...62217&p=594721

                  The solution to both questions is the same, and simple; but will not be provided in this thread. Please bump (add a reply yourself with 'Bump' or similar as the message text) your original post to bring it back to the top of the list and it will be answered ...

                  Comment


                  • #10
                    Re: Save Attachments From Outlook

                    Hi, I recommand my VBA app you can download it here : http://www.vbfrance.com/codes/OUTLOO...VER_54074.aspx
                    Juste need to activate few controls

                    Microsoft Date and Time Picker Control 6.0
                    Microsoft ProgressBar Control 6.0
                    Microsoft TreeView Control 6.0

                    And you'll find it here

                    http://support.microsoft.com/kb/297381

                    Comment


                    • #11


                      Save Attachments From Outlook

                      Hi ,

                      I got the code for saving attachment from outlook, but i want a code with a condition like if the subject is xyz then save the attachment, how to do this , please help me for the code.

                      Thanks
                      Lokesh

                      Comment

                      Working...
                      X