1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
| Option Explicit
Sub PPTlisteAgrSautPage()
'source : forum Developpez.com Auteur : Qwazerty
'insertion du code Devis qui fonctionne avec sauts de pages et test adaptation
'==============================================================================
Dim objPPT As PowerPoint.Application
Dim objPres As PowerPoint.Presentation
Dim objSld As PowerPoint.Slide
Dim objShp As PowerPoint.Shape
Dim ObjShTable As PowerPoint.Shape
Dim Tablo As Variant
Dim x As Integer, i As Integer, y As Integer
Dim TheRow As PowerPoint.Row
Dim NomTableau As String
Dim NewTop As Integer
Dim TheShTab As PowerPoint.Shape
Dim TmpTop As Integer
Dim NbrLigne As Byte
Dim AskNewSlide As Boolean, SameTableau As Boolean
Const cstNbrMaxLigne As Byte = 10
Dim NbrLigneAdded As Byte
Dim sTitre As String
With Sheets("AgrementsListeTriee")
Tablo = .Range("A2:Z" & .Cells(Rows.Count, "A").End(xlUp).Row).Value
End With
Set objPPT = CreateObject("Powerpoint.Application")
objPPT.Visible = True
Set objPres = objPPT.Presentations.Add
objPres.SaveAs ThisWorkbook.Path & "\Agrements.pptx"
'On charge le modele
'objPres.ApplyTemplate ThisWorkbook.Path & "\ListeAgr1.potx"
For i = 1 To UBound(Tablo)
'On regarde le nombre de lignes qui devront etre rajoutées au tableau
'Tablo(i,1) ne peut jamais etre vide, puisque tu te sert de cette colonne pour definir la taille de ton tableau
'If Tablo(i, 1) <> "" Then
NbrLigneAdded = 1
'NomTableau = "Liste récapitulative des agréments" '?? c'est utilisé num part
AskNewSlide = CBool(NbrLigne + NbrLigneAdded > cstNbrMaxLigne)
'SameTableau = CBool(NomTableau = Tablo(i, 2))
'On regarde si on doit créer un nouveau Slide ou completer l'existant
'If Not SameTableau Or AskNewSlide Then
If AskNewSlide Then
'RéInit
NbrLigne = 0
'sTitre = "Liste récapitulative des agréments"
'On garde en memoire le nom du tableau si celui-ci a change
'If Not SameTableau Then
' NomTableau = "Liste récapitulative des agréments"'?? c'est utilisé num part
'Else
' If AskNewSlide Then NomTableau = NomTableaut '?? quel interet
End If
'On ajoute un nouveau Slide
Set objSld = objPres.Slides.AddSlide(objPres.Slides.Count + 1, objPres.SlideMaster.CustomLayouts(6))
'On renseigne le titre du slide
objSld.Shapes.Title.TextFrame.TextRange.Text = "Liste récapitulative des agréments" 'NomTableau
objSld.Shapes.Title.TextFrame.TextRange.Font.Name = "brush script std"
objSld.Shapes.Title.TextFrame.TextRange.Font.Size = 20
'On crée le tableau qui contiendra les données avec 1 lignes 7 colonnes
Set ObjShTable = objSld.Shapes.AddTable(1, 7) 'NbrLigneAdded inutile d'utiliser une variable si tu as toujours qu'une ligne a rajouter
'On ajoute le nombre de ligne à ajouter au total de ligne du tableau
NbrLigne = NbrLigne + 1 'NbrLigneAdded
'On formate le tableau avec un style vierge
ObjShTable.Table.ApplyStyle "{2D5ABB26-0587-4C30-8999-92F81FD0307C}", True
With ObjShTable
.Left = 35
.Top = 100
End With
'On regarde si des objet tableau existe et on le rajoute a la suite du plus bas
'NewTop = ObjShTable.Top
'For Each TheShTab In objSld.Shapes
'If TheShTab.HasTable And (TheShTab.Name <> ObjShTable.Name) Then
'TmpTop = TheShTab.Top + TheShTab.Height
'If NewTop < TmpTop Then NewTop = TmpTop + 3
'End If
'Next
'ObjShTable.Top = NewTop
'===============
'rajout du code liste qui fonctionne sans saut page :
'Pourquoi tu n'utilises plus ton objet table ? ObjShTable il represente ton tableau, tu n'as donc pas besoin de tester tous les Objet de ta feuille
For Each objShp In objSld.Shapes
If objShp.HasTable Then
With objShp.Table
Do
If Tablo(i, 1) <> "" Then 'Il ne sera jamais vide voir remarque plus haut
.Rows.Add
'On dimensionne la taille des colonnes
'Ton formatage de colonne doit se faire avant la boucle, il est fait une fois pour toute, pas la peinne de le refaire a chaque ajout de ligne
With ObjShTable.Table
.Columns(1).Width = 130 'designation
.Columns(2).Width = 50 'calibre
.Columns(3).Width = 100 'agrement
.Columns(4).Width = 200 'dénomination
.Columns(5).Width = 50 'catégorie
.Columns(6).Width = 50 'distance
.Columns(7).Width = 60 'actif
'On Rajoute les données
'pour chaque cellule, on aligne le texte, on détermine la taille de police, on remplit avec les données :
.Cell(1 + (1 * x), 1).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignLeft
.Cell(1 + (1 * x), 1).Shape.TextFrame.TextRange.Font.Size = 12
.Cell(1 + (1 * x), 1).Shape.TextFrame.TextRange.Text = Tablo(i, 2) 'désignation
.Cell(1 + (1 * x), 2).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignRight
.Cell(1 + (1 * x), 2).Shape.TextFrame.TextRange.Text = Tablo(i, 3) 'calibre
.Cell(1 + (1 * x), 2).Shape.TextFrame.TextRange.Font.Size = 12
.Cell(1 + (1 * x), 3).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignLeft
.Cell(1 + (1 * x), 3).Shape.TextFrame.TextRange.Text = (Tablo(i, 7) & " " & Tablo(i, 10) & " " & Tablo(i, 12) & " " & Tablo(i, 14) & " " & Tablo(i, 16)) 'Agrément1 Col F
.Cell(1 + (1 * x), 3).Shape.TextFrame.TextRange.Font.Size = 12
.Cell(1 + (1 * x), 4).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignLeft
.Cell(1 + (1 * x), 4).Shape.TextFrame.TextRange.Text = Tablo(i, 9) 'dénomination
.Cell(1 + (1 * x), 4).Shape.TextFrame.TextRange.Font.Size = 12
.Cell(1 + (1 * x), 5).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
.Cell(1 + (1 * x), 5).Shape.TextFrame.TextRange.Text = Tablo(i, 4) 'catégorie
.Cell(1 + (1 * x), 5).Shape.TextFrame.TextRange.Font.Size = 12
.Cell(1 + (1 * x), 6).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignRight
.Cell(1 + (1 * x), 6).Shape.TextFrame.TextRange.Text = (Tablo(i, 11) & " " & Tablo(i, 13) & " " & Tablo(i, 15) & " " & Tablo(i, 17)) 'distance1 Col K=11
.Cell(1 + (1 * x), 6).Shape.TextFrame.TextRange.Font.Size = 12
.Cell(1 + (1 * x), 7).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignRight
.Cell(1 + (1 * x), 7).Shape.TextFrame.TextRange.Text = Format(Tablo(i, 5), "# ##0.000") 'actif
.Cell(1 + (1 * x), 7).Shape.TextFrame.TextRange.Font.Size = 12
End With
End If
i = i + 1
x = x + 1
If i > UBound(Tablo) Then Exit Do
Loop While Tablo(i, 1) <> ""
End With
End If
Next
Next
objPres.Save
'objPres.Close
End Sub |
Partager