Consulting

Results 1 to 3 of 3

Thread: Send all files in folder vba

  1. #1

    Send all files in folder vba

    I am currently using the code attached to send a single file path. Would somebody be able to help me modify the code to send all files in a particular folder instead of just 1 file?
    Attached Files Attached Files

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    Ride the wind to the sun
    Posts
    2,571
    ?

    Sub vbax_61999_email_all_files_in_folder()
    
        Dim strFolder As String
        Dim fso As Object
        Dim fsoFolder As Object
        Dim fsoFile As Object
        
        Set fso = CreateObject("Scripting.FileSystemObject")
        
        With CreateObject("Outlook.Application")
            For i = 2 To Cells(Rows.Count, 2).End(xlUp).Row
                strFolder = Range("C" & i).Value
                If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"
                Set fsoFolder = fso.GetFolder(strFolder)
                With .CreateItem(olMailItem)
                    .To = Range("B" & i).Value
                    .Subject = Range("I2").Value
                    .Body = Range("J2").Value
                    For Each fsoFile In fsoFolder.Files
                        .Attachments.Add strFolder & fsoFile.Name
                    Next
                    .Display 'or 'Send
                End With
                Range("F" & i).Value = Format(Date, "mm/dd/yy")
            Next
        End With
    
    End Sub
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    Thank you for the help.

Posting Permissions

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