+ Reply to Thread
Results 1 to 13 of 13

attaching PDF files via a command button

  1. #1
    Registered User
    Join Date
    11-18-2019
    Location
    London, England
    MS-Off Ver
    10
    Posts
    5

    attaching PDF files via a command button

    Hi,

    I have a spreadsheet which I will require to attach and send PDF files.

    I need to create some functionality that a command button (or anything functional) will review a value of a particular cell and will attach the corresponding PDF files to an outgoing email.

    For example, if a customer as a code of EUK ; they have requested for UK and European charts, therefore based on that I will need to attach the UK and European PDF files to an email and be able to send the charts to the customers email address which will also be in the spreadsheet, for instance in cell C5

    Thanks in advance

  2. #2
    Valued Forum Contributor saravnepali's Avatar
    Join Date
    01-14-2019
    Location
    Sydney Australia
    MS-Off Ver
    2010
    Posts
    447

    Re: attaching PDF files via a command button

    Try macro like below attached to the command button
    Please Login or Register  to view this content.
    Last edited by saravnepali; 11-18-2019 at 11:11 AM.
    If you think someone helped you, click on the "* Add Reputation" as a way to say thank you.

    If your problem is solved, go to Thread Tools and select Mark This Thread Solved

  3. #3
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: attaching PDF files via a command button

    @saravnepali

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)

  4. #4
    Registered User
    Join Date
    11-18-2019
    Location
    London, England
    MS-Off Ver
    10
    Posts
    5

    Re: attaching PDF files via a command button

    Hi,

    many thanks for the sharing the logic.

    However, I have made slight adjustments to the code but it's not allowing me to send email beyond the first group selected in the conditional statements that is Europe only

    Sub email()
    Dim OutMail As Object
    'send email
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
    ' If SIGNATURE = True Then .display
    .To = ThisWorkbook.Sheets("Sheet1").Range("K10") '
    .Subject = "Black Monthly Reports"
    If ThisWorkbook.Sheets("Sheet1").Range("H12").Value = "E" Then
    .Attachments.Add "C:\Users\arazaq\Documents\Black\European Equity Index GBP June 2019.pdf"
    ElseIf ThisWorkbook.Sheets("Sheet1").Range("H12").Value = "ENA" Then
    .Attachments.Add "C:\Users\arazaq\Documents\Black\European Equity Index GBP June 2019.pdf C:\Users\arazaq\Documents\Black\North American Index GBP June 2019.pdf"
    ElseIf ThisWorkbook.Sheets("Sheet1").Range("H12").Value = "ENAP" Then
    .Attachments.Add "C:\Users\arazaq\Documents\Black\Continental European Equity Index Fund (UK) Class L ACCU GBP June 2019.pdf C:\Users\arazaq\Documents\Black\iShares North American Equity Index Fund (UK) L ACCU GBP June 2019.pdf C:\Users\arazaq\Documents\Black\iShares\iShares Pacific ex Japan Equity Index GBP June 2019.pdf"
    End If
    .Display 'or '.Send 'to send the email
    End With

    End Sub

    Many Thanks

  5. #5
    Valued Forum Contributor saravnepali's Avatar
    Join Date
    01-14-2019
    Location
    Sydney Australia
    MS-Off Ver
    2010
    Posts
    447

    Re: attaching PDF files via a command button

    Hi
    .Attachments.Add has to be added to each file to be attached

    Try this as per below

    Please Login or Register  to view this content.
    Or try the select case statement if you have many possible options to choose
    Please Login or Register  to view this content.
    Last edited by saravnepali; 11-18-2019 at 11:34 AM.

  6. #6
    Registered User
    Join Date
    11-18-2019
    Location
    London, England
    MS-Off Ver
    10
    Posts
    5

    Re: attaching PDF files via a command button

    Hi,

    many thanks for your help, it's much appreciated.

    however, I have tried the code above above, but when I change the value in cell H12 from 'E' to say 'ENA' then when i run the above macro there's no repsonse

    Many Thanks

    Adnan

  7. #7
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: attaching PDF files via a command button

    @adnan

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)

  8. #8
    Valued Forum Contributor saravnepali's Avatar
    Join Date
    01-14-2019
    Location
    Sydney Australia
    MS-Off Ver
    2010
    Posts
    447

    Re: attaching PDF files via a command button

    Quote Originally Posted by adnan_razaq View Post
    Hi,

    many thanks for your help, it's much appreciated.

    however, I have tried the code above above, but when I change the value in cell H12 from 'E' to say 'ENA' then when i run the above macro there's no repsonse

    Many Thanks

    Adnan
    Did you mean that it works when the cell value in H12 is 'E' and doesn't work when the value is 'ENA'

  9. #9
    Valued Forum Contributor saravnepali's Avatar
    Join Date
    01-14-2019
    Location
    Sydney Australia
    MS-Off Ver
    2010
    Posts
    447

    Re: attaching PDF files via a command button

    Quote Originally Posted by adnan_razaq View Post
    Hi,

    many thanks for your help, it's much appreciated.

    however, I have tried the code above above, but when I change the value in cell H12 from 'E' to say 'ENA' then when i run the above macro there's no repsonse
    Adna,
    Did you meant that code works fine if H12 value is 'E' and doesn't work when its value is 'ENA' ?

    That sounds strange.

    Is it possible to send your code or even attach the spreadsheet ?

  10. #10
    Registered User
    Join Date
    11-18-2019
    Location
    London, England
    MS-Off Ver
    10
    Posts
    5

    Re: attaching PDF files via a command button

    Hi Sarav,

    That's correct.

    When I change the value (it is a drop list field), from 'E' to say 'ENA' then it all falls over.

    please see the code below

    Please Login or Register  to view this content.
    Thank you


    Adnan

  11. #11
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: attaching PDF files via a command button

    @saravnepali
    This is the third warning you received in a fortnight.
    Please take note that any new infraction will be followed by temporary banning.
    Thanks

  12. #12
    Valued Forum Contributor saravnepali's Avatar
    Join Date
    01-14-2019
    Location
    Sydney Australia
    MS-Off Ver
    2010
    Posts
    447

    Re: attaching PDF files via a command button

    See my new code as above

    You have still repeated the same mistake

    You need to have the .attachments.add for each file you want to attach

    For "ENA" case above, you put to files for one line

    Replace
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    This should work
    Last edited by saravnepali; 11-18-2019 at 05:06 PM.

  13. #13
    Registered User
    Join Date
    11-18-2019
    Location
    London, England
    MS-Off Ver
    10
    Posts
    5

    Re: attaching PDF files via a command button

    Many Thanks for your assistance - all sorted !

+ 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: 4
    Last Post: 11-08-2018, 01:48 PM
  2. [SOLVED] Command button, save sheets from master workbook to separated new files.(And more)
    By GPMan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-05-2018, 05:48 AM
  3. Replies: 2
    Last Post: 02-02-2016, 10:27 PM
  4. VBA code to create command button. Print all sheets then delete command button.
    By Declamatory in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-15-2015, 05:18 PM
  5. Playing specific WAV files with a command button using a combobox value
    By Marc De Vlam in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-09-2013, 01:22 PM
  6. Attaching Standard Excel Command to Button
    By laguna92651 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-23-2012, 02:54 AM
  7. Replies: 1
    Last Post: 09-17-2007, 09:57 PM

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