VBA code to open SAVE AS dialogue box with Save As Type: PDF

Anonymous
2020-05-28T12:16:38+00:00

Hi,

I am looking for a VBA code to open the SAVE AS dialogue box with the suggested file type of "PDF".

I will then assign this macro to a rectangle shape that will serve as a button called "SAVE AS PDF" which the user can click to open the SAVE AS dialog box.

(I am only wanting to save the current worksheet to PDF, not the whole workbook).

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Anonymous
    2020-05-28T20:04:12+00:00

    BTW

    If you try the macro as in my first post the pdf files will be saved on the same folder the workbook you are currently using is.

    If you want a different path then use the last code I sent you

    1 person found this answer helpful.
    0 comments No comments
Answer accepted by question author
  1. Anonymous
    2020-05-28T19:59:58+00:00

    I meant like this

    *******************************************************************

    Sub SaveAsPDF()

    Dim fName, MyPath, currDate As String

    MyPath = "C:\Users\Darren\Desktop"

    fName = "Daily Worksheet"

    currDate = Format(Now, "dd.mm.yyyy-hhmmss")

    With ActiveSheet

        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=MyPath & fName & currDate & ".pdf", _

        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

    End With

    End Sub

    ************************************************************************************

    This macro will save on your desktop a .pdf file with this name pattern

    ex. "Daily Worksheet-28.05.2020-174548.pdf"   indicating the date and time the document was saved

    If you want to change the name to "Sales" then

    Change fName = "Daily Worksheet"

    with fName = "Sales"

    Therefore your pdf files will be stored under the name, ex. "Sales-28.05.2020-194548.pdf" indicating the Date and Time it was saved.

    I hope this macro will help you 

    Regards

    1 person found this answer helpful.
    0 comments No comments
Answer accepted by question author
  1. Anonymous
    2020-05-28T13:13:53+00:00

    Hi -

    Please try to add a comma between arguments, for example:

    ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, FileName:="sales.pdf", Quality:=xlQualityStandard, OpenAfterPublish:=True

    Note that this will not open the dialog but will save the file directly according to the arguments.

    Does this help your question? If yes, would you mark it as resolved and give a rating? Otherwise please let me know how I can further help you.

    Thank you!

    1 person found this answer helpful.
    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Anonymous
    2020-05-28T12:52:13+00:00

    Hi Darren,

    You would need to use Workbook.ExportAsFixedFormat method. More detailed documentation can be found here: https://docs.microsoft.com/en-us/office/vba/api...

    Does this help your question? If yes, would you mark it as resolved and give a rating? Otherwise please let me know how I can further help you.

    Thank you!

    0 comments No comments
  2. Anonymous
    2020-05-28T13:07:45+00:00

    Hi Elvissey,

    Thank you so much for the advice. However, I am unable to make it work....

    0 comments No comments