Attach multiple documents on one email by using document path

  • Dear all


    I'm using the code below, in outlook vba, It converts the File path link to PDF then creates an email, attach a file, and send the email. It works fine, except I can't figure out how to add multiple attachments to a single email?


    My File path is in Column F under Sheet1 as below. Every line relates one document in directory. Here is the sample lines ;


    \\SVR-Storage4\Accounts_Data\CM-Docs\B\P\1\BP1\214\Bill ref 245680_513897_1.docx
    \\SVR-Storage4\Accounts_Data\CM-Docs\C\H\A\CHA116\31\Bill ref 245675_513831_1.docx
    \\SVR-Storage4\Accounts_Data\CM-Docs\C\I\T\CIT13\312\Bill ref 245668_513786_1.docx
    \\SVR-Storage4\Accounts_Data\CM-Docs\C\O\F\COFW6\715\Bill ref 245669_513787_1.docx
    \\SVR-Storage4\Accounts_Data\CM-Docs\H\T\L\HTL1\288\Bill ref 245674_513812_1.docx
    \\SVR-Storage4\Accounts_Data\CM-Docs\H\T\L\HTL1\303\Bill ref 245673_513810_1.docx
    \\SVR-Storage4\Accounts_Data\CM-Docs\L\E\W\LEW23\22\Bill ref 245681_513898_1.docx


    The way it works at the moment ; when you open the excel form it automatically opens a UserForm which has Listview window. if you highlight a row it updates the various TextBoxes over the UserForm, TextBox5 has the invoice number, when you click "Email button" on the UserForm, it finds the whatever invoice number in the TextBox5 and matches with the invoice number under Column B on "invoice Sheet" then activates the path under Column E. The File path will find the invoice in the directory in word format then it will convert it to PDF and attach to an email.


    For multiple attachment I have crated another Sheet which is Sheet1. On the UserForm Listview window I select multiple rows then I click "List" button this will create a list on the Sheet1 for multiple attachments. You should also select multiple invoices on the UserForm list then click "List" button it will create multiple list on the Sheet1 for emailing to see the list


    So what is the best way to achieve by amending below code and get multiple PDF invoice on one email?

    Any help is greatly appreciated.



  • Re: Attach multiple documents on one email by using document path


    Hi..


    This is some general help to get you going in the right direction..


    As an example.. if x were a range that had multiple filepaths..


    Code
    For Each xx In x
                    Attch = xx
                    If Attch = "" Then Exit For
                    .Attachments.Add Attch
        Next xx


    btw.. your workbook is not 64 bit friendly... check out "ptrsafe" in google.

  • Re: Attach multiple documents on one email by using document path


    Hi Apo , thank you for getting back to me , I didn't realise you replied my post. I still not managed to solve this problem.


    I have created another Listview window which I called Listview2. From the first Listview window I select multiple rows then with click of a button I list the selected invoices to another sheet which I call "Multi".
    These selected invoices appear on Listview2 window with below code I try to attach selected rows' invoices to one email but still doesn't work. Could someone help me please?


    this is liestview2 pic


    [ATTACH=CONFIG]68772[/ATTACH]


    This is sheet Multi


    [ATTACH=CONFIG]68774[/ATTACH]



    this part of the code should make it work but when code run nothing happens


    Code
    Set R = Worksheets("Multi").Range("E2", _
    Worksheets("Multi").Range("E" & Rows.Count).End(xlUp))For i = 1 To ListView2.ListItems.Count
    '  If ListView2.ListItems(i).Checked = True Then
    If ListView2.ListItems(i).Selected = True Then
    SearchInv = ListView2.ListItems(i).SubItems(5)
    With R
    .NumberFormat = "0"
    .Value = .Value
    Set fnd = .Find(SearchInv.Value, LookAt:=xlWhole)
    End With
  • Re: Attach multiple documents on one email by using document path


    Hi all again
    Looks like no one will be able to solve my problem on this, I like to approach it differently, is there a way that I can do this by going into the directory and picking the individual invoices regarding the requested invoice number then attaching it as PDF on to one email

    For example ; “ \\SVR-Storage4\Accounts_Data\CM-Docs\B\P\1\BP1\214\Billref 245680_513897_1.docx “ this directory link can be broken down as C:\\SVR-Storage4\AccountsData\CM-Docs\ B is first letter of the client code and P is the second letter of the client code these 2 letter are folders by itself ,1 is the first number of the client code (this can be 2 or 3 numbers sometimes) this is also a folder , when whole of these folders selected it gives you another folder BP1 which contains the various matters under this client code , on this incident matter folder is 214 where the Bill ref 245680 is stored, the rest of the number is not needed.
    I have seen on some other forums that people managed to attach multiple documents by selecting the directory. Would it be possible to write a code which will pick up the invoice from the directory rather than the document path option (Colum F) as the document path option hasn’t worked?
    Thank you for your time

  • Re: Attach multiple documents on one email by using document path


    Hi All
    Finally I have cracked this problem and managed to attach more one than one file on an email (I didn't know it is this easy), the only problem I have is I had to point the exact cell number that had the path address. Is that a way that I can generalise the cell rather than saying B2,B3,B4,B5 ...ect? I want the macro see every cell path in Colum B until the empty cell and attach it to the email as PDF. Can you please help me on that?



    thanks

  • Re: Attach multiple documents on one email by using document path


    still not finalised yet, if someone help with my last question it will be done then :thumbup:

  • Re: Attach multiple documents on one email by using document path


    hello,
    change the range to suit

  • Re: Attach multiple documents on one email by using document path


    Thank you pike, it worked perfectly ,many many months' hard work paid off finally thanks to you.


    obviously if the range increased I need to increase the B2:B4 range. Would it be possible to do until the blank cell in B?


    Also it work so slow, is there way to speed it up?


    Kind regards

  • Re: Attach multiple documents on one email by using document path


    No vba is slow so if you have a lot of values add a doevents to allow the file creation time to synchronize to code

  • Re: Attach multiple documents on one email by using document path


    how much I thank you it wont be enough Pike, as I said you have solved a massive issue that I was trying to solve many, many months. It attaches 22 invoices in PDF format in one click.


    thank you very much again. Respect

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!