+ Reply to Thread
Results 1 to 14 of 14

VBA to send 2 sheets by email after converting to PDF

  1. #1
    Registered User
    Join Date
    05-17-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    6

    VBA to send 2 sheets by email after converting to PDF

    I am still a beginner to VBA in Excel. Have used it before but mostly from copying and pasting. This is one that I would love to be able to create. I have created a workbook that has about 6 or 7 sheets. Most of the time the person filling out the form will only want to send two sheets to another person. My hope is that I can create a button that has a macro that will copy those two sheets, save them as PDF and attach them in an email.

    Can someone show me how to do this? Not sure if I am asking too much but if they could post the code and I could just copy it. I know that they would have to save the file somewhere before the email would open and attach the files, and for now, is there a way to have it prompt you to where to save it? If the code requires the names of the tabs, I can edit that.

    If this can be done, I would be a hero around the office.

    Thank you for any help you can give.

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: VBA to send 2 sheets by email after converting to PDF

    All you ask can easily be done, just a few questions.

    1) Will it always be the same two sheets or would you like to be able to select them before you send the email ?
    2) Do you want the sheets in one or seperate pdf-files ?
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Registered User
    Join Date
    05-17-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: VBA to send 2 sheets by email after converting to PDF

    They would always be the same to worksheets. If it is possible to put them into two separate attachments that would be amazing, but if it is easier to put them together that is fine as well. That is not super important.

    Thank you very much for looking to help

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: VBA to send 2 sheets by email after converting to PDF

    OK bodie, get ready to be king of the office.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-17-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: VBA to send 2 sheets by email after converting to PDF

    you have gotten me very excited. I copied the code into a new Macro and changed the sheet names to the sheet names in the workbook. When I click on the button that I added the Macro to, i get the following message

    Compile Error:
    Invalid or unqualified Reference.

    It highlighted the below
    .AllowMultiSelect = False

    Thank you so much. I think this will really blow their minds. Sorry if I am making people laugh, but I work with a lot of people that are not too Excel knowledgeable.

    Did I copy something wrong? Did I do something wrong?

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: VBA to send 2 sheets by email after converting to PDF

    Post the altered code you are using now because this shouldn't happen.
    Attached Files Attached Files
    Last edited by bakerman2; 05-02-2017 at 12:47 PM.

  7. #7
    Registered User
    Join Date
    05-17-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: VBA to send 2 sheets by email after converting to PDF

    Here you go

    Sub Emailsheets()
    '
    ' Emailsheets Macro

    ' With Application.FileDialog(msoFileDialogFolderPicker)
    .AllowMultiSelect = False
    .InitialFileName = ThisWorkbook.Path & "\"
    If .Show <> -1 Then MsgBox "No folder selected! Exiting sub...": Exit Sub
    mypath = .SelectedItems(1) & "\"
    End With
    Sheets("ANALYSIS").ExportAsFixedFormat 0, mypath & Sheets("firstsheetname").Name 'change to suit twice
    Sheets("PROFORMA").ExportAsFixedFormat 0, mypath & Sheets("secondsheetname").Name 'change to suit twice
    With CreateObject("Outlook.Application").CreateItem(0)
    .to = "" 'change to suit
    .CC = ""
    .BCC = ""
    .Subject = "Pro-Forma For - " 'change to suit
    .Body = "Please see the attached Pro-Forma. Please review and let me know if you have any quesitons." 'change to suit
    .Attachments.Add mypath & Sheets("ANALYSIS").Name & ".pdf" 'change to suit
    .Attachments.Add mypath & Sheets("PROFORMA").Name & ".pdf" 'change to suit
    .Display '.Send
    End With
    End Sub

    '
    End Sub

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA to send 2 sheets by email after converting to PDF

    Please look at the forum rules about using code tags[/URL] (#3)...

    Your issue is the ' that you have before the first line... it is commenting out the "With...." and causing your error.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: VBA to send 2 sheets by email after converting to PDF

    This is what it should look like.

    Please Login or Register  to view this content.
    Also don't forget to fill in the emailaddress in the

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    05-17-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: VBA to send 2 sheets by email after converting to PDF

    Thank you both for your help. It is working. However just as you asked originally, if we want this in two separate attachments or combined into one, I thought they would want them in separate, but now some are asking to be combined. So I was going offer both options. How would I add it so that both are combined?

    Thank again. I am blown away by the knowledge of people like you both.

  11. #11
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: VBA to send 2 sheets by email after converting to PDF

    Give this a go.

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    05-17-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: VBA to send 2 sheets by email after converting to PDF

    Thank you, thank you, thank you. You have made my office very happy. I really appreciate your time. Thank you again for your help and patience.

  13. #13
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA to send 2 sheets by email after converting to PDF

    bakermam rocks

  14. #14
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: VBA to send 2 sheets by email after converting to PDF

    @ Arkadi

    I've seen you do some flashy stuff too so let's rock together .

    @ bodie

    You're very, very, very welcome.
    Enjoy the new status at the office.

+ 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. Send email with attachement sheets
    By Vishnu_agarwal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-05-2016, 08:30 PM
  2. Save Multiple Sheets as PDF then send in Email
    By liamtimms1985 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-19-2015, 06:03 AM
  3. Workflow with signatures (if cell=x then send email, if signed then send email)
    By Kate2811 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2014, 05:37 AM
  4. Zip excel sheets and send by email
    By Dennikim in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-10-2008, 06:00 AM
  5. formatted sheets get unformatted when send via email attachment?
    By TJ in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 11:05 AM
  6. [SOLVED] formatted sheets get unformatted when send via email attachment?
    By TJ in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 07:05 AM
  7. [SOLVED] formatted sheets get unformatted when send via email attachment?
    By TJ in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 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