Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

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


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


qui se trouve :

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

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


Récap des champs nommés :

Afin de cadrer l'impression du fichier PDF il est impératif de définir une zone d'impression




Création d'un bouton Macro :
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 :
 

Pièces jointes

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

Discussions similaires

Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…