+ Reply to Thread
Results 1 to 5 of 5

VBA that will send with mail all files from folder

Hybrid View

forfiett VBA that will send with mail... 08-24-2014, 09:24 AM
fredlo2010 Re: VBA that will send with... 08-24-2014, 10:56 AM
forfiett Re: VBA that will send with... 08-25-2014, 07:37 AM
fredlo2010 Re: VBA that will send with... 08-25-2014, 08:53 AM
forfiett Re: VBA that will send with... 08-26-2014, 02:46 PM
  1. #1
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    VBA that will send with mail all files from folder

    Good day to all.

    I need a code that will send with e-mail (outlook) all files from a defined folder. In that folder will be max 10 PDF files.

    Thanks in advance.

    Best regards,
    Forfiett

  2. #2
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: VBA that will send with mail all files from folder

    Hi,

    Maybe this

    Sub SendFilesInFolder()
    
        Dim otApp As Object
        Dim otEmail As Object
        
        Dim fso As Object
        Dim fsoFolder As Object
        Dim fsoFile As Object
        
        Const strFOLDER_PATH As String = "C:\Users\Alfred\Desktop\x"
        
        ' Initialize the variables
        Set otApp = CreateObject("Outlook.Application")
        Set otEmail = otApp.CreateItem(0)
        
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set fsoFolder = fso.GetFolder(strFOLDER_PATH)
        
        
        ' Create the email
        With otEmail
            .To = "my@gmail.com"
            .Subject = "Files Enclosed"
            .Body = "Pleasse find attached the requested files."
            
            ' Loop through the files in folder and add them
            For Each fsoFile In fsoFolder.Files
                .Attachments.Add fsoFile.Path, 1
            Next
            
            .Display
            
            ' If you want to send it directly then uncomment below
            '.Send
            
        End With
        
        ' Clean up
        Set otApp = Nothing
        Set otEmail = Nothing
        Set fso = Nothing
        Set fsoFolder = Nothing
        Set fsoFile = Nothing
        
        
    End Sub
    Thanks

  3. #3
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    Re: VBA that will send with mail all files from folder

    Dear,

    thanks, it is working perfectly..but it is possible to use HTMLBody..how to do it?

  4. #4
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: VBA that will send with mail all files from folder

    Hi,

    Try this. Now heads up HTMLbody can be a headache lol Things not always come out the way you want them to so you might need to play with the HTML section of the body for a bit before you get expected output.

    Option Explicit
    
    Sub SendFilesInFolder()
    
        Dim otApp As Object
        Dim otEmail As Object
        
        Dim fso As Object
        Dim fsoFolder As Object
        Dim fsoFile As Object
        
        Const strFOLDER_PATH As String = "C:\Users\Alfred\Desktop\x"
        
        ' Initialize the variables
        Set otApp = CreateObject("Outlook.Application")
        Set otEmail = otApp.CreateItem(0)
        
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set fsoFolder = fso.GetFolder(strFOLDER_PATH)
        
        
        ' Create the email
        With otEmail
            .To = "my@gmail.com"
            .Subject = "Files Enclosed"
            .BodyFormat = 2
            .HTMLBody = "<HTML><BODY><b>Please</b> find attached the requested files. </BODY></HTML>"
                
            ' Loop through the files in folder and add them
            For Each fsoFile In fsoFolder.Files
                .Attachments.Add fsoFile.path, 1
            Next
            
            .Display
            
            ' If you want to send it directly then uncomment below
            '.Send
            
        End With
        
        ' Clean up
        Set otApp = Nothing
        Set otEmail = Nothing
        Set fso = Nothing
        Set fsoFolder = Nothing
        Set fsoFile = Nothing
        
    End
    Thanks

  5. #5
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    Re: VBA that will send with mail all files from folder

    Dear,

    Thanks for help. Suggest to use HTML5, as bellow:

    "<span style='font-family:calibri;font-size:11pt'>" & "Good day," & "<br"> & _

    Best regards,
    forfiett

+ 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. How to Send automated mails with attachment files saved in a folder?
    By yemnirmal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-20-2014, 03:16 PM
  2. Replies: 1
    Last Post: 03-11-2014, 12:24 PM
  3. [SOLVED] attach file from folder on c:\ to outlook mail and send
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-24-2013, 11:33 AM
  4. Macro code should find inv no in folder and send attachhed mail.
    By visha_1984 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-30-2013, 07:55 AM
  5. How to e-mail selected row and use e-mail address in a cell to send e-mail from excel
    By syedalamgir in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-27-2010, 02:15 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