"Save as PDF Button" saving PDF as workbook name not specified name.

destitog

New Member
Joined
Aug 4, 2017
Messages
2
Hi all new here but I am trying to create a button that will export and invoice to a PDF file that a user can name as they please. Currently the save as box comes up but regardless of what is typed it save it as the workbook name. Any and all help is appreciated. Code is below.

Private Sub CommandButton1_Click()
Dim sPath As String
Dim sFile As Variant
Dim ws As Worksheet
On Error GoTo ErrHandle
sPath = ThisWorkbook.Path & "" & "Quote" & Me.Range("g7")

sFile = Application.GetSaveAsFilename _
(InitialFileName:=sPath, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and File Name to save")
If sFile = "False" Then
MsgBox ("Please Choose A File Name")
Exit Sub
End If

Me.ExportAsFixedFormat _
Type:=xlTypePDF, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
Exit Sub
ErrHandle:
MsgBox ("Document Not Saved")
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Welcome to the forum...

I think you're missing the FileName portion of the export command.
Code:
Me.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Quality:=xlQualityStandard, _
[B][COLOR=#ff0000]    FileName:= sFile, _[/COLOR][/B]
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=True
Exit Sub
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

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