how to generate a worksheet into pdf when saving the excel?

akika

New Member
Joined
Aug 2, 2018
Messages
10
Office Version
  1. 2016
hi
pls help

In excel, i have 7 sheets.
When i save the excel file save or ctrl s,

how can i generate sheet 2 named 'calculation' in pdf format with a datetimestamp in a specific folder ?

file name: worksheetName<datetimestmp>.pdf
folder D:\test\
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try:
Code:
Sub SavePDF()
    ChDir "D:\test\"
    Sheets("Sheet2").ExportAsFixedFormat Type:=xlTypePDF, Filename:="calculation" & Replace(Format(Now(), "yyyy-mm-dd,h:mm AM/PM"), ":", ".") _
        , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub
 
Upvote 0
im new to vba things.
1 more question pls
how can i put this code when the save button is click (file > save or ctrl S).
then it directly save the pdf wzout hving to click on run macro.
 
Upvote 0
You can assign a short cut key to run the macro. Do the following:
-In the "View" tab in the top menu, click "Macros" at the far right.
-Click on "SavePDF" and click the "Options" button.
-Enter any letter such as the letter "s" in the box.
-Click "OK" and close the pop-up.
Now whenever you want to run the macro, hold down the CTRL key and press the letter "s" and the macro will run.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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