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

akika

New Member
Joined
Aug 2, 2018
Messages
4
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\
 

Some videos you may like

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.

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
9,541
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
 

akika

New Member
Joined
Aug 2, 2018
Messages
4
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.
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
9,541
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,108,816
Messages
5,525,064
Members
409,617
Latest member
Lenaf

This Week's Hot Topics

Top