XL 2016 macro exporter en PDF feuilles visibles

MC88

XLDnaute Nouveau
Bonjour,

j'ai trouvé une macro afin de sélectionner dans mon sommaire les feuilles qui doivent être visible ou non.

Je souhaiterais que lorsque je clic sur l'image "impression" qu'uniquement les feuilles visibles soient exporter en PDF.

Est-ce que quelqu'un a une solution?
Merci d'avance pour votre aide!
 

Pièces jointes

  • draft rapport.xlsm
    56.6 KB · Affichages: 23

kiki29

XLDnaute Barbatruc
Salut, à adapter à ton contexte
VB:
Option Explicit

Sub Tst()
Dim Wsh As Worksheet, sFichier As String
    For Each Wsh In ThisWorkbook.Worksheets
        If Wsh.Visible And FeuilleVide(Wsh.Name) = False Then
            sFichier = ThisWorkbook.Path & "\" & Wsh.Name & ".pdf"
            Wsh.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sFichier, _
                                    Quality:=xlQualityStandard, _
                                    IncludeDocProperties:=True, _
                                    IgnorePrintAreas:=False, _
                                    OpenAfterPublish:=False
        End If
    Next Wsh
End Sub

Private Function FeuilleVide(sNomFeuille As String) As Boolean
    FeuilleVide = False
    If WorksheetFunction.CountA(Worksheets(sNomFeuille).UsedRange) = 0 And _
       Worksheets(sNomFeuille).Shapes.Count = 0 Then
        FeuilleVide = True
    End If
End Function
 
Dernière édition:

kiki29

XLDnaute Barbatruc
Salut, voir ici
dans ton cas ceci devrait suffire :

VB:
Sub FusionPDF()
Dim Ar() As Variant, j As Long
Dim Wsh As Worksheet, sFichier As String, sNom As String

    Application.ScreenUpdating = False
    For Each Wsh In ThisWorkbook.Worksheets
        If Wsh.Visible And FeuilleVide(Wsh.Name) = False Then
            ReDim Preserve Ar(j)
            Ar(j) = Wsh.Name
            j = j + 1
        End If
    Next Wsh

    ThisWorkbook.Sheets(Ar).Select
    sNom = ThisWorkbook.Path & "\" & "Fusion.pdf"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sNom, _
                                    Quality:=xlQualityStandard, _
                                    IncludeDocProperties:=True, _
                                    IgnorePrintAreas:=False, _
                                    OpenAfterPublish:=False
    ThisWorkbook.Sheets(1).Select
    Erase Ar
    Application.ScreenUpdating = True
End Sub

Private Function FeuilleVide(sNomFeuille As String) As Boolean
    FeuilleVide = False
    If WorksheetFunction.CountA(Worksheets(sNomFeuille).UsedRange) = 0 And _
       Worksheets(sNomFeuille).Shapes.Count = 0 Then
        FeuilleVide = True
    End If
End Function
 
Dernière édition:

lidem

XLDnaute Nouveau
bonjour moi j'ai un soucis avec on code vba au niveau de limpression. est ce que vous pouvez m'aider a le corriger.
Sub devis_imprimer()
Dim wb As Workbook, feuille As Worksheet
Dim plage As String, nomDocument As String, dossierAdresse As String
Dim iVis As XlSheetVisibility

Set wb = ThisWorkbook
Set feuille = wb.Sheets("Devis")
dossierAdresse = Sheets("Parameters").Range("K9").Value & "\"
nomDocument = feuille.Range("J10").Value

'Mettre à plage l adresse de la plage à imprimer
plage = "$C$6:$M$53"

Application.ScreenUpdating = False

With feuille.PageSetup
.PrintArea = plage
.FitToPagesTall = 1
.FitToPagesWide = 1 'Set FitToPagesWide to 1
.LeftMargin = Application.InchesToPoints(0)
.RightMargin = Application.InchesToPoints(0)
.TopMargin = Application.InchesToPoints(0)
.BottomMargin = Application.InchesToPoints(0)
End With


With feuille
iVis = .Visible
.Visible = xlSheetVisible
.Activate
.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=dossierAdresse & nomDocument & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
.Visible = iVis
End With

Application.ScreenUpdating = True

End Sub

l'erreur se situe a partir de ".ExportAsFixedFormat Type:=xlTypePDF"
 

Discussions similaires

Statistiques des forums

Discussions
311 720
Messages
2 081 904
Membres
101 834
dernier inscrit
Jeremy06510