+ Reply to Thread
Results 1 to 5 of 5

Macro that Selects Specific Excel Worksheets to a PDF file & Saves to the User's Desktop

  1. #1
    Registered User
    Join Date
    04-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    3

    Macro that Selects Specific Excel Worksheets to a PDF file & Saves to the User's Desktop

    I would for the following code to be associated with a button (I know how to assign macros to buttons). When the user selects the button, the macro will perform the following:

    1.) Select the worksheets titled "Cover Page", "Authorization for Cap Project", "Financial Inputs" and "Capital Budgets";
    2.) Saved the selected worksheets as a pdf on the user's desktop with the file name " ' Project_Name' - CAR - 'TodayDate' ". "Project Name" and "TodayDate" are named cells within the workbook.
    3.) The pdf version of the the selected worksheets will be displayed.
    4.) A message box will appear that states, "The displaying pdf file has been saved on your desktop under the name "' Project_Name' - CAR - 'TodayDate'". Please keep this file name for all future correspondence."
    - Remember "Project_Name" & "TodayDate" have are named cells in the workbook
    5.) Return to the original worksheet where the button is located.

    Sub SaveAsPDF()

    Dim OriginalSheet As String

    OriginalSheet = ActiveSheet.Name

    Sheets(Array("Cover Page", "Authorization for Cap Project", "Financial Inputs", _
    "Capital Budget")).Select
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
    "C:\Desktop" & Range("Project_Name").Value & " - CAR - " & Range("TodayDate").Value & ".pdf", Quality:= _
    xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
    OpenAfterPublish:=True

    Sheets(OriginalSheet).Select

    MsgBox "The displaying pdf file has been saved to your Desktop under the name " & Range("Project_Name").Value & " - CAR - " & Range("TodayDate").Value & ".pdf" & _
    " Please keep this file name for all future correspondence"

    End Sub


    Thank you so much Excel/VBA Gurus and to the creators of this site. ExcelForum is life(job)-saving!

  2. #2
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: Macro that Selects Specific Excel Worksheets to a PDF file & Saves to the User's Deskt

    Where are you getting hung up?

    First, I would set OpenAfterPublish to False unless you want users to review the PDF and close it themselves. Second, it looks like you're setting OriginalSheet as the active sheet, and then telling the code to select an array of sheets. If this is true, wouldn't that mean OriginalSheet will equal all of the sheets you just activated?(just thinking out loud here) Rather than declaring the variable, maybe change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    and change "Sheet1" to whatever your actual sheet name is that you want to select. You'll want to avoid using "Select" or "activate" as much as possible

    Try this out (untested)

    Please Login or Register  to view this content.
    Change "Sheet1" to the sheet you want to activate at the end
    Last edited by VBA FTW; 01-29-2013 at 06:39 PM.

  3. #3
    Registered User
    Join Date
    04-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Macro that Selects Specific Excel Worksheets to a PDF file & Saves to the User's Deskt

    Thank you for your prompt response; however, I'm receiving Error 400 now. Doesn't that error have to do with the array? Thanks again!

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Macro that Selects Specific Excel Worksheets to a PDF file & Saves to the User's Deskt

    @Excel Wet Behind Ear,

    Moderators Note:
    We would love to continue to help you with your query, but first, before we can proceed, please see Forum Rule #3 about code tags and adjust accordingly...
    HTH
    Regards, Jeff

  5. #5
    Registered User
    Join Date
    04-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Macro that Selects Specific Excel Worksheets to a PDF file & Saves to the User's Deskt

    Thanks for the note, Jeffrey.

    Below is my code in the proper format:


    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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