+ Reply to Thread
Results 1 to 3 of 3

Macro to attach Zip Files within sub-folders

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2024
    Posts
    2,873

    Macro to attach Zip Files within sub-folders

    I have code to attach zip files within sub-folders with C:\Sales Reports in Microsoft outlook



    The code works well and attaches some of the zip files in Outlook as the maximum limit is 20MB




    I need my code amended to attach up to a max limit of 20MB and when this is reached to create a second to attach the balance of the zip files (the total off al the Zip files is less than 40MB so I only need two emails)


    Your assistance in this regard is most appreciated



     Sub CreateEmail()
    '---------------------------------------------------
    'DECLARE AND SET VARIABLES
        Dim outApp As Object
        Dim OutMail As Object
        Dim strbody As String
        Dim Filename As String
        Set outApp = CreateObject("Outlook.Application")
        Set OutMail = outApp.CreateItem(0)
    '---------------------------------------------------
    'CREATE EMAIL BODY
          strbody = "Hi " & Join(Application.Transpose(Range("D1:D5").Value)) & vbNewLine & vbNewLine
                strbody = strbody & "Attached Please find latest Sales Reports" & vbNewLine & vbNewLine
                strbody = strbody & "Regards" & vbNewLine & vbNewLine
    '---------------------------------------------------
    'BUILD EMAIL
        On Error Resume Next
        With OutMail
               .to = Join(Application.Transpose(Range("E1:E5").Value), ";")
            .CC = ""
            .BCC = ""
            .Subject = "Sales Reports"
            .Body = strbody
            Path = "C:\Sales Reports\"
    '--------------------------------------------
    'GET FILENAMES
    '        Filename = Dir(Path & "*.zip")
    '        Do While Len(Filename) > 0
    '            .Attachments.Add Filename
    '            Filename = Dir
    '        Loop
            
        Dim fso, oFolder, oSubfolder, oFile, col As Collection
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set col = New Collection
        col.Add fso.GetFolder(Path)
    
        Do While col.Count > 0
            Set oFolder = col(1)
            col.Remove 1
            For Each oSubfolder In oFolder.SubFolders
                col.Add oSubfolder
            Next oSubfolder
            For Each oFile In oFolder.Files
                           If CStr(oFile) Like "*.zip" Then
                    .Attachments.Add CStr(oFile)
                End If
    
            Next oFile
        Loop
            .Display
        End With
    '---------------------------------------------------
    'CLEANUP
        On Error GoTo 0
        Set OutMail = Nothing
        Set outApp = Nothing
        Set fso = Nothing
    End Sub

    I have also posted on https://www.myonlinetraininghub.com/...folders#p18655
    Attached Files Attached Files
    Last edited by Howardc1001; 01-26-2021 at 09:54 PM.

  2. #2
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2024
    Posts
    2,873

    Re: Macro to attach Zip Files within sub-folders

    There are 18 Zip files within the sub-folders

    As an alternative to my request is to attach the first 10 files to the first email and the balance to the second email

  3. #3
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2024
    Posts
    2,873

    Re: Macro to attach Zip Files within sub-folders

    See solution https://www.myonlinetraininghub.com/...folders#p18718

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro to select Files to attach
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-12-2020, 11:44 AM
  2. [SOLVED] Macro to attach all files in a folder
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-27-2019, 09:01 AM
  3. Replies: 5
    Last Post: 11-02-2018, 03:15 AM
  4. Attach files created by macro to an email
    By JesseSingh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-04-2016, 12:12 AM
  5. Use Excel VBA to Copy multiple files from different source folders to different folders
    By mm1234mail in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2014, 01:17 PM
  6. Replies: 1
    Last Post: 09-12-2013, 09:23 PM
  7. Excel Email Macro - HELP! - Need to be able to attach two different files
    By benwahchang in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-29-2013, 08:41 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1