EXCEL :: Exporter un onglet/plage de cellules dans un fichier PDF

oguruma

XLDnaute Occasionnel
Pour reprendre ce fichier issu du post nous allons générer une fiche de stock au format PDD pour chaque produit.
Exemple
1712061754643.png


Déjà on constate que la liste déroulante est bien associée au filtre.
Elle est construite à partir de :
1712061853049.png


qui se trouve :
1712061935569.png

avec la formule : =UNIQUE(TB_STOCK[ELEMENT])

Afin de lister les produits à imprimer on passe par ce champ nommé :
1712062024329.png


Récap des champs nommés :
1712062070251.png

Afin de cadrer l'impression du fichier PDF il est impératif de définir une zone d'impression
1712062152092-png.1194124


1712062205969.png


Création d'un bouton Macro :
1712062235627.png

Affectation de la Macro MAIN()
VB:
Option Explicit
Sub MAIN(Optional sDumy As String)
    Dim vAppel As Variant
    Dim sType As String
   
    On Error GoTo HANDLE_ERROR

    sType = TypeName(Application.Caller)
    Select Case sType
        Case "Range"
            vAppel = Application.Caller.Address
        Case "String"
            vAppel = Application.Caller
        Case "Error"
            vAppel = sDumy
        Case Else
            vAppel = sDumy
    End Select

    Select Case vAppel
        Case "SH_SAVE_PDF"
            Call SAVE_TO_PDF
    End Select

FIN:
    MsgBox "Fiches imprimées"
    Exit Sub
   
HANDLE_ERROR:
    MsgBox "Erreur " & Err.Description
    Resume FIN
End Sub

Sub SAVE_TO_PDF()

    Const WK_FICHE = "Fiche de stock"
    Const FOLDER = "D:\DATA\10__DEVELOPPEMENTS__EXCEL__LABS\§__LAB04_FICHE_STOCK_PDF"
    Const LIST_FRUITS = "LIST_FRUITS"
    Const LIST_FRUIT_UNIQUE = "LIST_FRUIT_UNIQUE"
   
    Dim wks As Worksheet
    Dim rFruit As Range
    Dim rList As Range
    Dim lngRowsCount As Long
    Dim iFruit As Long
    Dim sFilePathPDF As String
    Dim sTempFile As String

    Application.ScreenUpdating = False
    Set wks = ActiveWorkbook.Worksheets(WK_FICHE)
    Set rFruit = wks.Range(LIST_FRUITS)
    Set rList = Range(LIST_FRUIT_UNIQUE)
    sFilePathPDF = FOLDER & "\" & "Fiche_De_Stock_[PARSE].pdf"
    lngRowsCount = rList.CurrentRegion.Rows.Count - 2
    For iFruit = 1 To lngRowsCount
        rFruit.Value = rList.Offset(iFruit - 1, 0).Value
        sTempFile = Replace(sFilePathPDF, "[PARSE]", rFruit.Value)
        wks.ExportAsFixedFormat _
             Type:=xlTypePDF, _
             Filename:=sTempFile, _
             Quality:=xlQualityStandard, _
             IncludeDocProperties:=True, _
             IgnorePrintAreas:=False, _
             OpenAfterPublish:=False
    Next iFruit
    Application.ScreenUpdating = True
End Sub

exemple de fiche :
1712062499799.png
 

Pièces jointes

  • 1712061896001.png
    1712061896001.png
    2.1 KB · Affichages: 1
  • 1712062152092.png
    1712062152092.png
    7.1 KB · Affichages: 24
  • LAB_FICHE_STOCK_PDF.V0.02.xlsm
    42.3 KB · Affichages: 1

Discussions similaires

Statistiques des forums

Discussions
312 243
Messages
2 086 551
Membres
103 246
dernier inscrit
blablasss