Title: Excel Macro Save As PDF Filename bug
Tags: excel;vba;pdf
Question: Recently, I need to automate the file saving features inside Excel file and I manage to rig up basic macro that can save as PDF
Source: https://exceloffthegrid.com/vba-code-save-excel-file-as-pdf/ and https://www.contextures.com/excelvbapdf.html

Here is macro. The idea is user can save the current sheet in any folder locations that they want as PDF files.

The bugs looks like this. Supposedly , I have file named A report template.xlsm and I keyin the name that I wanted to save for example Marketing - 15_5_2022.pdf in a folder. 
Somehow, after saving, the file name will revert back to A report template.pdf instead of Marketing - 15_5_2022.pdf

Any ideas where do I go wrong in the codes? 

```Sub SaveAsPDF()

Dim PdfFilename As Variant

PdfFilename = Application.GetSaveAsFilename( _
    InitialFileName:="Dept - Due Date", _
    FileFilter:="PDF, *.pdf", _
    Title:="Save Report As PDF")

If PdfFilename <&gt; False Then

    ActiveSheet.ExportAsFixedFormat _
        Type:=PdfFilenme, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=False, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=True

End If

End Sub
```

Comment: Don't forget, filenames can't contain / or \ so you'll need to reformat your dates.

Comment: Good point, CLR. I edit the question for corrections.

Here is the accepted answer: You are not setting the name of the file to be saved. Try:

```ActiveSheet.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=PdfFilename, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=False, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=True
```

Regards,



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:05/12/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<excel><vba><pdf>', 'Title': 'Excel Macro Save As PDF Filename bug', 'ViewCount': 280, 'id': 61748538, 'user_AboutMe': None, 'user_AccountId': 14923467.0, 'user_DisplayName': 'Alan QA', 'user_Reputation': 15.0, 'user_Views': 3.0, 'user_id': 10775042.0}}