PDA

View Full Version : [SOLVED] Save a certain sheet as PDF and name it from a range within the sheet



djemy1975
04-19-2016, 01:47 AM
Deat Developpers,

What I want to do here with my userform is to save a sheet named "Facture Simple" as PDF file ,for later use,which I succeeded to do so far using this code:

Private Sub CommandButton15_Click()Dim ws As Worksheet
Dim strPath As String
Dim myFile As Variant
Dim strFile As String
On Error GoTo errHandler
Set ws = Sheets("Facture Simple")
'enter name and select folder for file
' start in current workbook folder
strFile = Replace(Replace(ws.Name, " ", ""), ".", "_") _
& "_" & Format(Now(), "yyyymmdd\_hhmm") & ".pdf"
strFile = ThisWorkbook.Path & "\" & strFile
myFile = Application.GetSaveAsFilename _
(InitialFileName:=strFile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and FileName to save")
If myFile <> "False" Then
ws.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
MsgBox "La facture a été enregistrée en PDF format."
End If
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file"
Resume exitHandler

But I have to name pdf file from a range in this sheet ("E14").Could it be possible?

Thanks in advance,

djemy1975
04-19-2016, 02:25 AM
It is solved .Thanks for all who showed interest.

By insterting the following code:


strFile = Replace(ws.Range("E14"), " ", "") & ".pdf"