Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 35

Thread: Attachment Download

  1. #21
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    6,874
    Post Thanks / Like
    Mentioned
    83 Post(s)
    Tagged
    15 Thread(s)

    Default Re: Attachment Download

    or #16 ?
    Regards Dante Amor

  2. #22
    Board Regular
    Join Date
    Aug 2012
    Posts
    438
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Attachment Download

    Quote Originally Posted by DanteAmor View Post
    Try this please:

    Run the macro and select the folder that contains the emails.

    Code:
    Sub download_attachments()
      Dim olApp As Outlook.Application, olmail As MailItem, Att As Object
      Dim olFolder As Outlook.Folder, sPath As String, y As Long, strfile As String
      sPath = ThisWorkbook.Path & "\"
      '
      Set olApp = CreateObject("Outlook.application")
      Set olmail = olApp.CreateItem(olMailItem)
      Set olFolder = olApp.GetNamespace("MAPI").PickFolder
      '
      For Each olmail In olFolder.Items
        If TypeName(olmail) = "MailItem" Then
          y = 1
          For Each Att In olmail.Attachments
            strfile = sPath & olmail.Attachments.Item(y).Filename
            olmail.Attachments.Item(y).SaveAsFile strfile
            y = y + 1
          Next Att
        End If
      Next
      MsgBox "Done"
    End Sub
    getting error on olApp As Outlook.Application -- "user-defined type not defined"

  3. #23
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    6,874
    Post Thanks / Like
    Mentioned
    83 Post(s)
    Tagged
    15 Thread(s)

    Default Re: Attachment Download

    To automate Outlook based tasks from Excel you need to add Outlook Object Library (Microsoft Outlook XX.X Object Library) in Excel References. You can follow below steps to add Outlook reference in Excel VBA:

    1. From the Menu Bar, click on Tools > References

    2. Select ‘Microsoft Outlook XX.X Object Library’ and click on ‘OK’ button
    Last edited by DanteAmor; Oct 20th, 2019 at 02:04 PM.
    Regards Dante Amor

  4. #24
    MrExcel MVP ZVI's Avatar
    Join Date
    Apr 2008
    Location
    Sevastopol
    Posts
    3,654
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Attachment Download

    Quote Originally Posted by vmjan02 View Post
    getting error on olApp As Outlook.Application -- "user-defined type not defined"
    In fact, this should not happen if the code is in the Outlook module,
    as it was mentioned in the first post:
    Quote Originally Posted by vmjan02 View Post
    I have the below code and have it is on Outlook VBA on ThisOutlookSession
    So where actually the code is?
    What version of MS Office are you using?
    Vladimir Zakharov

  5. #25
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    6,874
    Post Thanks / Like
    Mentioned
    83 Post(s)
    Tagged
    15 Thread(s)

    Default Re: Attachment Download

    Quote Originally Posted by ZVI View Post
    What version of MS Office are you using?

    @AMvmjan02 said:
    Using Outlook 2010. and there is no subfolder its in the inbox folder
    Regards Dante Amor

  6. #26
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    6,874
    Post Thanks / Like
    Mentioned
    83 Post(s)
    Tagged
    15 Thread(s)

    Default Re: Attachment Download

    Another update, try this please.

    Code:
    Sub download_attachments()
      'Dim olApp As Outlook.Application, olmail As MailItem, Att As Object
      Dim olApp As Object, olmail As Object, Att As Object
      Dim olFolder As Object, sPath As String, y As Long, strfile As String
      sPath = ThisWorkbook.Path & "\"
      '
      Set olApp = CreateObject("Outlook.application")
      Set olmail = olApp.CreateItem(0)
      Set olFolder = olApp.GetNamespace("MAPI").PickFolder
      '
      For Each olmail In olFolder.Items
        If TypeName(olmail) = "MailItem" Then
          y = 1
          For Each Att In olmail.Attachments
            strfile = sPath & olmail.Attachments.Item(y).Filename
            olmail.Attachments.Item(y).SaveAsFile strfile
            y = y + 1
          Next Att
        End If
      Next
      MsgBox "Done"
    End Sub
    Regards Dante Amor

  7. #27
    Board Regular
    Join Date
    Aug 2012
    Posts
    438
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Attachment Download

    Quote Originally Posted by ZVI View Post
    In fact, this should not happen if the code is in the Outlook module,
    as it was mentioned in the first post:

    So where actually the code is?
    What version of MS Office are you using?
    Code is not in outlook module. and version is 2010

  8. #28
    MrExcel MVP ZVI's Avatar
    Join Date
    Apr 2008
    Location
    Sevastopol
    Posts
    3,654
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Attachment Download

    Quote Originally Posted by vmjan02 View Post
    Code is not in outlook module. and version is 2010
    Thanks for the clarification, but please bear in mind that my code posted in this thread should be in the ThisOutlookSession Outlook's module.
    Last edited by ZVI; Oct 21st, 2019 at 10:53 AM.
    Vladimir Zakharov

  9. #29
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    6,874
    Post Thanks / Like
    Mentioned
    83 Post(s)
    Tagged
    15 Thread(s)

    Default Re: Attachment Download

    Hi @vmjan02,
    Did you try the codes again? in post #26 or the previous code with the reference update.
    Regards Dante Amor

  10. #30
    Board Regular
    Join Date
    Aug 2012
    Posts
    438
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Attachment Download

    Quote Originally Posted by ZVI View Post
    Thanks for the clarification, but please bear in mind that my code posted in this thread should be in the ThisOutlookSession Outlook's module.
    yes. its there only.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •