Consulting

Results 1 to 2 of 2

Thread: Save a certain sheet as PDF and name it from a range within the sheet

  1. #1

    Save a certain sheet as PDF and name it from a range within the sheet

    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,

  2. #2
    It is solved .Thanks for all who showed interest.

    By insterting the following code:

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •