+ Reply to Thread
Results 1 to 7 of 7

VBA to send max 10 pdf files from specific folder to one email

  1. #1
    Registered User
    Join Date
    05-20-2022
    Location
    Mauritius
    MS-Off Ver
    10
    Posts
    9

    VBA to send max 10 pdf files from specific folder to one email

    Hi All,

    It is my first time here and really struggling to find the solution for the below. Basically, I have a folder with around 900 pdf files. We need to send per mail, a maximum of 10 pdfs to one email add. Could I please have the vba which will keep sending 10 pdf to the same email address ( with an option to cc another email add), until all the pdfs have been sent in the folder, with a pop-up message at the end stating that all mails have been sent.

    Thanking you all for your help.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: VBA to send max 10 pdf files from specific folder to one email

    Try such code:

    Please Login or Register  to view this content.
    Best Regards,

    Kaper

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: VBA to send max 10 pdf files from specific folder to one email

    Answering the question in PM:

    I don't see a reason why the code shall stop at:
    Please Login or Register  to view this content.
    with Run-time Error 438

    Just in case I am attaching a file with this macro. MAy be try to run it from the file attached. For your convenience the parameters (folder path and mail addresses) are taken from the cells in worksheet.

    Let us know if this works (PS. try with folder with less than 900 files :-) and probably your own address as recipient :-) )
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    05-20-2022
    Location
    Mauritius
    MS-Off Ver
    10
    Posts
    9

    Re: VBA to send max 10 pdf files from specific folder to one email

    Hi Kaper,

    Thank you so much for your help! I think I got the error message as I tried to run the vba from outlook rather than excel. This is exactly what I needed! Thank you!! Just one more thing, is there any way for the vba to automatically pick up your mail signature?

    Thank you again ))

  5. #5
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: VBA to send max 10 pdf files from specific folder to one email

    If you mean your signature as defined in Outlook have a look in a folder which name is similar to:
    C:\Users\Deepa0102\AppData\Roaming\Microsoft\Signatures to check whether there is a file with htm extension, like Mysig.htm
    If it's there, the code of send_mails procedure could look like:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    05-20-2022
    Location
    Mauritius
    MS-Off Ver
    10
    Posts
    9

    Re: VBA to send max 10 pdf files from specific folder to one email

    Hi Kaper,

    I modified as per above but I am getting a 'Compile Error- Sub or Function not defined'. And the following are highlighted:

    Sub send_mails(fromfolder As String, recipient As String, Optional ccrecipient As String)
    Signature = GetBoiler

    Am I missing something please?

    Thank you again

  7. #7
    Registered User
    Join Date
    05-20-2022
    Location
    Mauritius
    MS-Off Ver
    10
    Posts
    9

    Re: VBA to send max 10 pdf files from specific folder to one email

    Hi Kaper,

    I managed to find out what was wrong. I needed to add the following under the End Sub:
    Function GetBoiler(ByVal sFile As String) As String
    Dim fso As Object
    Dim ts As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
    GetBoiler = ts.readall
    ts.Close
    End Function

    Now it is picking up the signature.

    Thanking you again for all your help.

+ 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. Replies: 1
    Last Post: 01-28-2019, 06:55 PM
  2. VBA code to send all PDF files in particular folder
    By krpraveen123 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-25-2017, 09:59 AM
  3. [SOLVED] Adjust email macro to send only select files in a folder rather than all ref'ed in a range
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-12-2016, 07:37 PM
  4. [SOLVED] VBA that will send with mail all files from folder
    By forfiett in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-26-2014, 02:46 PM
  5. Send data from Excel in email from specific email account
    By eriknokc in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-05-2007, 05:02 PM
  6. Replies: 1
    Last Post: 01-24-2006, 11:00 AM
  7. Replies: 1
    Last Post: 01-24-2006, 12:25 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