+ Reply to Thread
Results 1 to 6 of 6

Command button to save as pdf

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-19-2020
    Location
    Greece
    MS-Off Ver
    office 365
    Posts
    125

    Command button to save as pdf

    Hi to all,

    I need your Help.
    I created a command button on my excel file and i want to save the active sheet as pdf on desktop when i click on it.
    Thank you.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,512

    Re: Command button to save as pdf

    You can do by record macro
     Private Sub Btn_Click()
      Call macro1
     End sub
    "Presh Star Who has help you *For Add Reputation!! And mark case as Solve"

  3. #3
    Forum Contributor
    Join Date
    03-19-2020
    Location
    Greece
    MS-Off Ver
    office 365
    Posts
    125

    Re: Command button to save as pdf

    I have no idea about VBA, I will only write this code?

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,479

    Re: Command button to save as pdf

    Try

    Private Sub CommandButton1_Click()
    Dim saveLocation As String, fileName As String
    fileName = "myPDFFile.pdf"    ' <<<< CHANGE as needed
    saveLocation = "C:\Users\xxxx\OneDrive\Desktop\" & fileName ' <<<< CHANGE as needed
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
          fileName:=saveLocation
    End Sub
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  5. #5
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,743

    Re: Command button to save as pdf

    Into sheet code:

    Private Sub CommandButton1_Click()
    Call SavePDF4Me
    End Sub
    into module:

    Sub SavePDF4Me()
    Dim MyRng As Range
    Dim MyFile As String
    
    Set MyRng = ActiveSheet.[A1:O21]
    MyFile = Environ("userprofile") & "\Desktop\MyPDFFromExcel.pdf"
    
    MyRng.ExportAsFixedFormat _
                    Type:=xlTypePDF, _
                    Filename:=MyFile, _
                    Quality:=xlQualityStandard, _
                    IncludeDocProperties:=True, _
                    IgnorePrintAreas:=False
    
    End Sub
    Check attached file.
    Attached Files Attached Files
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  6. #6
    Forum Expert
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,512

    Re: Command button to save as pdf

    Private sub CommandButton1()
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
    fileName:=Createobject("WScript.Shell").SpecialFolders("Desktop") & "\MyPdf.pdf"
    End sub

+ 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. That Save Button/Command
    By Titantula in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-19-2018, 11:43 PM
  2. [SOLVED] Command save button?
    By A108A108 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-14-2016, 08:05 PM
  3. [SOLVED] 'Save' or 'save as' Command Button VBA Excel
    By eemiller1997 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-07-2013, 04:09 PM
  4. Command Button Save vs Save as
    By brharrii in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-10-2012, 04:39 PM
  5. Command Button To Save & Clear
    By Mooseman60 in forum Access Programming / VBA / Macros
    Replies: 2
    Last Post: 04-30-2011, 07:38 AM
  6. Command button to save
    By troysie in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-31-2011, 04:26 AM
  7. Save Command Button Help!
    By EnGo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2006, 04:55 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