+ Reply to Thread
Results 1 to 9 of 9

Need Help with Macro to Save two sheets to PDF

  1. #1
    Registered User
    Join Date
    11-17-2016
    Location
    OK
    MS-Off Ver
    365
    Posts
    19

    Smile Need Help with Macro to Save two sheets to PDF

    Need some help from you guys please. I've tried searching and found some examples of what I'm trying to do, but I know little to nothing about Macros so it doesn't make much sense. Here's what I have:

    I've got multiple sheets (input, data, proposal, and terms) and I need to print/save to PDF two of the sheets (Proposal and Terms) when you click a Print button (which I have created). I want to click the button, assign file name based on cell A1 of sheet 1, and save to folder where excel sheet is saved. I know this is probably simple, but I'm stuck. Thanks in advance!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need Help with Macro to Save two sheets to PDF

    Something like this, change the highlighted part to FALSE if you don't want the PDF to appear onscreen after it is created:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,292

    Re: Need Help with Macro to Save two sheets to PDF

    Shouldn't it be like this?

    Please Login or Register  to view this content.
    Edit: Just tested it, no need to add & ".pdf" since it apparently comes automatic.
    Last edited by bakerman2; 11-17-2016 at 11:30 AM.
    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.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need Help with Macro to Save two sheets to PDF

    Correct. Also, including all the additional parameters in the Export command is useful long term to remember/see exactly what can be tweaked if you're interested.

  5. #5
    Registered User
    Join Date
    11-17-2016
    Location
    OK
    MS-Off Ver
    365
    Posts
    19

    Re: Need Help with Macro to Save two sheets to PDF

    PERFECT! Thank you very much guys!

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need Help with Macro to Save two sheets to PDF

    As it appears you've reached a conclusion, I've marked this thread SOLVED for you.
    FYI, this is done through the Thread Tools located above the first post in this thread. Thanks.

  7. #7
    Registered User
    Join Date
    11-17-2016
    Location
    OK
    MS-Off Ver
    365
    Posts
    19

    Re: Need Help with Macro to Save two sheets to PDF

    Bringing this back to life. I've added a second print button that will print 3 sheets, but they aren't printing in the order that I need. They are listed in the correct order in the macro but it's printing 1, 3, 2.

    Sub Print_Proposal_wBOM()
    Dim fPATH As String, fNAME As String

    fPATH = ThisWorkbook.Path & Application.PathSeparator
    fNAME = Sheets(2).Range("A1").Value

    Sheets(Array("Proposal", "Terms", "BOM")).Select

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    fPATH & fNAME, Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, _
    OpenAfterPublish:=True

    Sheets("Input").Activate

    End Sub

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: Need Help with Macro to Save two sheets to PDF

    Have a look here. Garry's Student has the answer for that by the looks of it.
    http://stackoverflow.com/questions/2...specific-order

  9. #9
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Need Help with Macro to Save two sheets to PDF

    As jolivanes showed in the link, a change in sheet index order governs.

    Other ways are:
    1. Export the sheets to a blank/scratch workbook in order to suit.
    2. Export each sheet to a pdf file and then merge in a specific order using a third party application calls to Acrobat, PDFcreator, PDFtk, etc.

+ 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. Press Save - Hide Sheets (before saving) - Actually Save - Unhide Sheets Again
    By MixedupExcel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-28-2015, 07:22 AM
  2. Macro Help Needed - Save only sheets with data as a pdf
    By dougjeffries in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-19-2015, 10:51 AM
  3. Replies: 2
    Last Post: 09-19-2013, 04:22 AM
  4. [SOLVED] Macro to save sheets as different workbooks on save
    By BridgeCat in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-09-2012, 08:10 AM
  5. conflict between auto save&close macro and show/hide sheets macro
    By alexandruc in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-18-2009, 11:56 AM
  6. macro to save specific sheets to destination
    By excellentexcel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-13-2009, 09:20 AM
  7. [SOLVED] How do I save macro so it's there for all Excel sheets?
    By Save a macro in Excel in forum Excel General
    Replies: 2
    Last Post: 09-22-2005, 04:05 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