Save as PDF Button

Surferol

New Member
Joined
Apr 9, 2021
Messages
17
Office Version
  1. 365
Platform
  1. MacOS
Hi all,

I would like to make a button on each sheet of a workbook which will save the sheet (excluding the button) as a PDF to the desktop.
Each sheets starts off as a blank sheet, the blank sheet is copied and data entered, sheet renamed as needed.

The data on each sheet will be reviewed and amended every few months at which point a new PDF needs to be produced to be saved (another program will store the PDF to be displayed over mapping)

I want to click a "Save As PDF" button which will save the sheet to PDF on the desktop, and name the file the same as the TAB name.
(basically taking away multiple clicks and sources of error of saving the wrong name to the wrong place.

Hope this is possible,
Thanks
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
For each button, assign the following macro. Note that if your desktop already has a file with the same name, it will be overwritten.

VBA Code:
Sub SaveAsPDF()

    Dim oWSHShell As Object
    Set oWSHShell = CreateObject("WScript.Shell")
    
    Dim saveAsFolder As String
    saveAsFolder = oWSHShell.SpecialFolders("Desktop")
    
    With ActiveSheet
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveAsFolder & "\" & .Name & ".pdf"
    End With
    
    Set oWSHShell = Nothing
    
End Sub

Hope this helps!
 
Upvote 0
Hi Domenic,
Forgive me, this is my first attempt at any form of macro or VBA.
I had a Macro recorded and opened VBA to enter what you show above and doesn't seem to work.
 

Attachments

  • Screen Shot 2021-05-09 at 13.38.19.png
    Screen Shot 2021-05-09 at 13.38.19.png
    78.5 KB · Views: 31
  • Screen Shot 2021-05-09 at 13.38.45.png
    Screen Shot 2021-05-09 at 13.38.45.png
    126.3 KB · Views: 31
Upvote 0
Instead of
saveAsFolder = oWSHShell.SpecialFolders("Desktop")

Try
saveAsFolder ="C:\Foldername\Foldername\"

It's probably the difference between Windows and MacOS that causes this.
 
Upvote 0
Your button is calling some other routine. You have to assign SaveAsPDF macro to the form button or put that word into your activex control. Which it is depends on your command button's control type.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top