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

Ligne VBA pour imprimer plusieur feuilles excel dans un même PDF

cedric cadre

XLDnaute Nouveau
Bonjour,

voila, je désire créeer un bouton sur mon excel dans le feuille "impression" qui me permettre d'imprimer un PDf avec les feuilles désirées, celles ci sont cochées dans ma feuille impression (dans la colone B).

ma macro donne ceci :

Sub ImpressionGlobale()


If Sheets("Impression").Range("B3").Value <> "" Then Sheets("Calcul Global").PrintOut
If Sheets("Impression").Range("B4").Value <> "" Then Sheets("ALEO").PrintOut
If Sheets("Impression").Range("B5").Value <> "" Then Sheets("AGsun").PrintOut
If Sheets("Impression").Range("B6").Value <> "" Then Sheets("KINGSPAN").PrintOut
If Sheets("Impression").Range("B7").Value <> "" Then Sheets("HYE").PrintOut
If Sheets("Impression").Range("B8").Value <> "" Then Sheets("HYE").PrintOut
If Sheets("Impression").Range("B9").Value <> "" Then Sheets("HYE").PrintOut
If Sheets("Impression").Range("B10").Value <> "" Then Sheets("SILIKEN").PrintOut
If Sheets("Impression").Range("B11").Value <> "" Then Sheets("Boitier").PrintOut
If Sheets("Impression").Range("B12").Value <> "" Then Sheets("DEVIS").PrintOut
If Sheets("Impression").Range("B13").Value <> "" Then Sheets("presentation").PrintOut
If Sheets("Impression").Range("B14").Value <> "" Then Sheets("Calcul PV").PrintOut
If Sheets("Impression").Range("B15").Value <> "" Then Sheets("Page1").PrintOut
If Sheets("Impression").Range("B16").Value <> "" Then Sheets("PageN").PrintOut

End Sub

le problème c'est que cela me génère autant d'impression PDF que de feuilles, or je ne veut qu'un seul PDF en sortie.

j'ai trouvé cette ligne de commande sur internet :

Sheets(Array("Feuil2", "Feuil3")).PrintOut Copies:=1

je souhaiterai pouvoir l'adapter à mon cas précis car je pense que cela doit être la solution, mais je n'arrive pas à trouver comment faire.

Des idées?

Merci pour vos réponses.
 

cavo789

XLDnaute Nouveau
Re : Ligne VBA pour imprimer plusieur feuilles excel dans un même PDF

Salut,

Je verrais un truc du style

Option Base 1

Dim arrSheets as variant
Dim I As byte

I = 0
if ..... then I = I + 1 : Redim Preserve arrSheets(I) : arrSheets(I) = Sheets("Calcul Global")
if ..... then I = I + 1 : Redim Preserve arrSheets(I) : arrSheets(I) = Sheets("ALEO")

et ainsi de suite, puis

Sheets(arrSheets).PrintOut Copies:=1

Non testé
 

cedric cadre

XLDnaute Nouveau
Re : Ligne VBA pour imprimer plusieur feuilles excel dans un même PDF

Salut cavo et merci pour ta réponse, je suis en train de désesperer de trouver une solution...

pour l'instant j'en suis a :

Sub ImpressionGlobale()



If Sheets("Impression").Range("B3").Value <> "" Then Sheets("Calcul Global").Select Replace:=False
If Sheets("Impression").Range("B4").Value <> "" Then Sheets("ALEO").Select Replace:=False
If Sheets("Impression").Range("B5").Value <> "" Then Sheets("AGsun").Select Replace:=False
If Sheets("Impression").Range("B6").Value <> "" Then Sheets("KINGSPAN").Select Replace:=False
If Sheets("Impression").Range("B7").Value <> "" Then Sheets("HYE").Select Replace:=False
If Sheets("Impression").Range("B8").Value <> "" Then Sheets("HYE").Select Replace:=False
If Sheets("Impression").Range("B9").Value <> "" Then Sheets("HYE").Select Replace:=False
If Sheets("Impression").Range("B10").Value <> "" Then Sheets("SILIKEN").Select Replace:=False
If Sheets("Impression").Range("B11").Value <> "" Then Sheets("Boitier").Select Replace:=False
If Sheets("Impression").Range("B12").Value <> "" Then Sheets("DEVIS").Select Replace:=False
If Sheets("Impression").Range("B13").Value <> "" Then Sheets("presentation").Select Replace:=False
If Sheets("Impression").Range("B14").Value <> "" Then Sheets("Calcul PV").Select Replace:=False
If Sheets("Impression").Range("B15").Value <> "" Then Sheets("Page1").Select Replace:=False
If Sheets("Impression").Range("B16").Value <> "" Then Sheets("PageN").Select Replace:=False

SelectedSheets.PrintOut Copies:=1

End Sub


mais évidmeent ça ne marche pas....

je vais tester ta solution et je fais un retour dans quelques minutes.
 

cedric cadre

XLDnaute Nouveau
Re : Ligne VBA pour imprimer plusieur feuilles excel dans un même PDF

ça ne marche pas, apparement il y a une "instruction incorrecte à l'exterieur d'une procédure" et la ligne I = 0 à l'air de lui déplaire puisqu'elle est surlignée.
 

cavo789

XLDnaute Nouveau
Re : Ligne VBA pour imprimer plusieur feuilles excel dans un même PDF

I=0 ne peut pas lui déplaire C'est une bête assignation d'une valeur à une variable.

Maintenant, ce qui lui déplait c'est "instruction incorrecte à l'exterieur d'une procédure" : il était sous-entendu que tu copies/colles le code que je propose dans une procédure.
 

cedric cadre

XLDnaute Nouveau
Re : Ligne VBA pour imprimer plusieur feuilles excel dans un même PDF

ok, j'en suis a ça :

Sub ImpressionGlobale()

Option Base 1

Dim arrSheets As Variant
Dim I As Byte

I = 0
If Sheets("Impression").Range("B3").Value <> "" Then I = I + 1: ReDim Preserve arrSheets(I): arrSheets(I) = Sheets("Calcul Global")
If Sheets("Impression").Range("B3").Value <> "" Then I = I + 1: ReDim Preserve arrSheets(I): arrSheets(I) = Sheets("Calcul Global")
If Sheets("Impression").Range("B4").Value <> "" Then I = I + 1: ReDim Preserve arrSheets(I): arrSheets(I) = Sheets("ALEO")
If Sheets("Impression").Range("B5").Value <> "" Then I = I + 1: ReDim Preserve arrSheets(I): arrSheets(I) = Sheets("AGsun")
If Sheets("Impression").Range("B6").Value <> "" Then I = I + 1: ReDim Preserve arrSheets(I): arrSheets(I) = Sheets("KINGSPAN")
If Sheets("Impression").Range("B7").Value <> "" Then I = I + 1: ReDim Preserve arrSheets(I): arrSheets(I) = Sheets("HYE")
If Sheets("Impression").Range("B8").Value <> "" Then I = I + 1: ReDim Preserve arrSheets(I): arrSheets(I) = Sheets("HYE")
If Sheets("Impression").Range("B9").Value <> "" Then I = I + 1: ReDim Preserve arrSheets(I): arrSheets(I) = Sheets("HYE")
If Sheets("Impression").Range("B10").Value <> "" Then I = I + 1: ReDim Preserve arrSheets(I): arrSheets(I) = Sheets("SIKILEN")
If Sheets("Impression").Range("B11").Value <> "" Then I = I + 1: ReDim Preserve arrSheets(I): arrSheets(I) = Sheets("Boitier")
If Sheets("Impression").Range("B12").Value <> "" Then I = I + 1: ReDim Preserve arrSheets(I): arrSheets(I) = Sheets("DEVIS")
If Sheets("Impression").Range("B13").Value <> "" Then I = I + 1: ReDim Preserve arrSheets(I): arrSheets(I) = Sheets("presentation")
If Sheets("Impression").Range("B14").Value <> "" Then I = I + 1: ReDim Preserve arrSheets(I): arrSheets(I) = Sheets("Calcul PV")
If Sheets("Impression").Range("B15").Value <> "" Then I = I + 1: ReDim Preserve arrSheets(I): arrSheets(I) = Sheets("Page1")
If Sheets("Impression").Range("B16").Value <> "" Then I = I + 1: ReDim Preserve arrSheets(I): arrSheets(I) = Sheets("PageN")

Sheets(arrSheets).PrintOut Copies:=1

End Sub


mais toujours instruction incorrecte... dans le procédure cette foir, j'avai oublié les SUB et end sub
 

cedric cadre

XLDnaute Nouveau
Re : Ligne VBA pour imprimer plusieur feuilles excel dans un même PDF

C'est bon j'ai trouvé la solution :

Sub ImpressionGlobale()


If Sheets("Impression").Range("B3").Value <> "" Then Sheets("Calcul Global").Select Replace:=False
If Sheets("Impression").Range("B4").Value <> "" Then Sheets("ALEO").Select Replace:=False
If Sheets("Impression").Range("B5").Value <> "" Then Sheets("AGsun").Select Replace:=False
If Sheets("Impression").Range("B6").Value <> "" Then Sheets("KINGSPAN").Select Replace:=False
If Sheets("Impression").Range("B7").Value <> "" Then Sheets("HYE").Select Replace:=False
If Sheets("Impression").Range("B8").Value <> "" Then Sheets("HYE").Select Replace:=False
If Sheets("Impression").Range("B9").Value <> "" Then Sheets("HYE").Select Replace:=False
If Sheets("Impression").Range("B10").Value <> "" Then Sheets("SILIKEN").Select Replace:=False
If Sheets("Impression").Range("B11").Value <> "" Then Sheets("Boitier").Select Replace:=False
If Sheets("Impression").Range("B12").Value <> "" Then Sheets("DEVIS").Select Replace:=False
If Sheets("Impression").Range("B13").Value <> "" Then Sheets("presentation").Select Replace:=False
If Sheets("Impression").Range("B14").Value <> "" Then Sheets("Calcul PV").Select Replace:=False
If Sheets("Impression").Range("B15").Value <> "" Then Sheets("Page1").Select Replace:=False
If Sheets("Impression").Range("B16").Value <> "" Then Sheets("PageN").Select Replace:=False

Sheets("Page1").Activate
ChDir "C:\Users\pose soleil\Desktop\Offre Particuliers ASE"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\pose soleil\Desktop\Offre Particuliers ASE\pdf.pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True

End Sub
 

Discussions similaires

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