Ik snap dat jullie denken dat het onmogelijk zo groot kan zijn. Echter was de opdracht van mijn stagebedrijf heel duidelijk: zo modulair mogelijk houden.
Zij willen bijvoorbeeld 1 cell kunnen aanpassen naar hun wensen ipv dat alles mee veranderd.
De code:
In het eerste deel wordt alles gedefinieerd en wordt een nieuwe PowerPoint bestand gepakt om alles in te zetten.
Sub Test1()
'First we declare the variables we will be using
Dim newPowerPoint As PowerPoint.Application
Dim activeSlide As PowerPoint.Slide
Dim cht As Excel.ChartObject
'Define worksheets
Set wb = ThisWorkbook
Set WSIndex = wb.Worksheets(1)
Set WSNumOfOpp = wb.Worksheets(6)
Set WSFleetPerfOne = wb.Worksheets(7)
Set WSFleetPerfTwo = wb.Worksheets(

Set WSATA = wb.Worksheets(9)
Set WSBench = wb.Worksheets(10)
'Look for existing instance
On Error Resume Next
Set newPowerPoint = GetObject(, "PowerPoint.Application")
'Let's create a new PowerPoint
If Err.Number <> 0 Then
Set newPowerPoint = CreateObject("PowerPoint.Application")
End If
'Disable error handling
On Error GoTo 0
'Show the PowerPoint
newPowerPoint.Visible = True
'Make a presentation in PowerPoint
newPowerPoint.Presentations.Open Filename:=wb.Path & "\KLM Template.pptx"
newPowerPoint.Activate
In het volgende stuk begint de tabel.
Eerste het uiterlijk bepalen: 12 rijen, 17 kolommen.
'Table
Set Data = newPowerPoint.ActivePresentation.Slides(2).Shapes.AddTable(12, 17)
With Data
'General
.Table.ApplyStyle "{5940675A-B579-460E-94D1-54222C63F5DA}", True
.Left = 15
.Height = 20
.Top = 230
.Fill.ForeColor.RGB = RGB(255, 255, 255)
TableFontSize = 9
ColoredColumns = RGB(243, 200, 167)
'Merging
.Table.cell(1, 4).Merge MergeTo:=.Table.cell(1, 5)
.Table.cell(1, 6).Merge MergeTo:=.Table.cell(1, 7)
.Table.cell(1,

.Merge MergeTo:=.Table.cell(1, 9)
.Table.cell(1, 10).Merge MergeTo:=.Table.cell(1, 11)
.Table.cell(1, 12).Merge MergeTo:=.Table.cell(1, 13)
.Table.cell(1, 14).Merge MergeTo:=.Table.cell(1, 15)
.Table.cell(1, 16).Merge MergeTo:=.Table.cell(1, 17)
.Table.cell(1, 1).Merge MergeTo:=.Table.cell(2, 1)
.Table.cell(1, 2).Merge MergeTo:=.Table.cell(2, 2)
.Table.cell(1, 3).Merge MergeTo:=.Table.cell(2, 3)
Dan het eerste kolom invullen:
'Column 1: Rank
.Table.cell(1, 1).Shape.TextFrame.TextRange.Text = WSIndex.Cells(1, 3)
.Table.cell(1, 1).Shape.TextFrame.TextRange.Font.Name = "Verdana Body"
.Table.cell(1, 1).Shape.TextFrame.TextRange.Font.Size = TableFontSize
.Table.cell(1, 1).Shape.TextFrame.TextRange.Font.Bold = True
.Table.cell(1, 1).Shape.TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0)
.Table.Columns(1).Width = 50
'Layout
.Table.Columns(1).Cells.Borders(ppBorderTop).ForeColor.RGB = RGB(0, 155, 225)
.Table.Columns(1).Cells.Borders(ppBorderLeft).ForeColor.RGB = RGB(0, 155, 225)
.Table.Columns(1).Cells.Borders(ppBorderRight).ForeColor.RGB = RGB(0, 155, 225)
.Table.Columns(1).Cells.Borders(ppBorderBottom).ForeColor.RGB = RGB(0, 155, 225)
.Table.cell(1, 2).Shape.Fill.ForeColor.RGB = ColoredColumns
.Table.cell(1, 1).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
.Table.cell(2, 1).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
.Table.cell(3, 1).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
.Table.cell(4, 1).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
.Table.cell(5, 1).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
.Table.cell(6, 1).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
.Table.cell(7, 1).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
.Table.cell(8, 1).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
.Table.cell(9, 1).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
.Table.cell(10, 1).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
.Table.cell(11, 1).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
.Table.cell(12, 1).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
'Font Size
.Table.cell(2, 1).Shape.TextFrame.TextRange.Font.Size = TableFontSize
.Table.cell(3, 1).Shape.TextFrame.TextRange.Font.Size = TableFontSize
.Table.cell(4, 1).Shape.TextFrame.TextRange.Font.Size = TableFontSize
.Table.cell(5, 1).Shape.TextFrame.TextRange.Font.Size = TableFontSize
.Table.cell(6, 1).Shape.TextFrame.TextRange.Font.Size = TableFontSize
.Table.cell(7, 1).Shape.TextFrame.TextRange.Font.Size = TableFontSize
.Table.cell(8, 1).Shape.TextFrame.TextRange.Font.Size = TableFontSize
.Table.cell(9, 1).Shape.TextFrame.TextRange.Font.Size = TableFontSize
.Table.cell(10, 1).Shape.TextFrame.TextRange.Font.Size = TableFontSize
.Table.cell(11, 1).Shape.TextFrame.TextRange.Font.Size = TableFontSize
.Table.cell(12, 1).Shape.TextFrame.TextRange.Font.Size = TableFontSize
'Top 10
One = WSIndex.Cells(3, 3)
Two = WSIndex.Cells(4, 3)
Three = WSIndex.Cells(5, 3)
Four = WSIndex.Cells(6, 3)
Five = WSIndex.Cells(7, 3)
Six = WSIndex.Cells(8, 3)
Seven = WSIndex.Cells(9, 3)
Eight = WSIndex.Cells(10, 3)
Nine = WSIndex.Cells(11, 3)
Ten = WSIndex.Cells(12, 3)
.Table.cell(3, 1).Shape.TextFrame.TextRange.Text = One
.Table.cell(4, 1).Shape.TextFrame.TextRange.Text = Two
.Table.cell(5, 1).Shape.TextFrame.TextRange.Text = Three
.Table.cell(6, 1).Shape.TextFrame.TextRange.Text = Four
.Table.cell(7, 1).Shape.TextFrame.TextRange.Text = Five
.Table.cell(8, 1).Shape.TextFrame.TextRange.Text = Six
.Table.cell(9, 1).Shape.TextFrame.TextRange.Text = Seven
.Table.cell(10, 1).Shape.TextFrame.TextRange.Text = Eight
.Table.cell(11, 1).Shape.TextFrame.TextRange.Text = Nine
.Table.cell(12, 1).Shape.TextFrame.TextRange.Text = Ten
En deze code wordt ook gebruikt om alle verdere kolommen in te vullen.
Dit moet dus 17 keer gebeuren. Als jullie een betere manier hebben, dan hoor ik het uiteraard graag. Dan zou het alsnog allemaal in 1 module kunnen
Groeten, Ganesh