Hi All,
I'm trying to, out of an excel spreadsheet, creat a neat presentation in powerpoint (if you are familiar to transaction tombstones within banking/M&A you might know what I'm heading for).
Thus: I have an excel sheet with transaction information. One transaction per row. I have created a VB script creating textboxes with this information based of actual filtering I want to do. Now I would like to send these textboxes to Powerpoint and arrange them in a good looking way. The amount of textboxes might be from 1-100 basically. Since about 9-12 will fit on one PPT-slide I need to loop a script that create a new slide every X textbox (or tombstone...)
Anyone who has done this before? Or have any ideas?
I have managed to send textboxes to powerpoint, however, I got only one (in the topleft corner) on each slide.
Thanks in advance!
/emil.
I'm trying to, out of an excel spreadsheet, creat a neat presentation in powerpoint (if you are familiar to transaction tombstones within banking/M&A you might know what I'm heading for).
Thus: I have an excel sheet with transaction information. One transaction per row. I have created a VB script creating textboxes with this information based of actual filtering I want to do. Now I would like to send these textboxes to Powerpoint and arrange them in a good looking way. The amount of textboxes might be from 1-100 basically. Since about 9-12 will fit on one PPT-slide I need to loop a script that create a new slide every X textbox (or tombstone...)
Anyone who has done this before? Or have any ideas?
I have managed to send textboxes to powerpoint, however, I got only one (in the topleft corner) on each slide.
Thanks in advance!
/emil.
Code:
Sub CreatePowerPoint()
'Add a reference to the Microsoft PowerPoint Library by:
'1. Go to Tools in the VBA menu
'2. Click on Reference
'3. Scroll down to Microsoft PowerPoint X.0 Object Library, check the box, and press Okay
'First we declare the variables we will be using
Dim newPowerPoint As PowerPoint.Application
Dim activeSlide As PowerPoint.Slide
Dim cht As Excel.ChartObject
'Look for existing instance
On Error Resume Next
Set newPowerPoint = GetObject(, "PowerPoint.Application")
On Error GoTo 0
'create a new PowerPoint
If newPowerPoint Is Nothing Then
Set newPowerPoint = New PowerPoint.Application
End If
'Make a presentation in PowerPoint
If newPowerPoint.Presentations.Count = 0 Then
newPowerPoint.Presentations.Add
End If
'Show the PowerPoint
newPowerPoint.Visible = True
'Loop through each chart in the Excel worksheet and paste them into the PowerPoint
'Dim m As Integer
'For m = 1 To 9
' ActiveSheet.OLEObjects("TextBox" & i).Visible = True
' Next m
' Dim ByI As Integer
' For ByI = 1 To 100000 in ActiveSheet.OLEObjects("TextBox " & ByI).objects.=True
' newPowerPoint.ActivePresentation.Slides.Add newPowerPoint.ActivePresentation.Slides.Count + 1, ppLayoutText
' newPowerPoint.ActiveWindow.View.GotoSlide newPowerPoint.ActivePresentation.Slides.Count
' Set activeSlide = newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Slides.Count)
' oTextBox1.Select
' oTextBox1.Copy
' activeSlide.Shapes.PasteSpecial(DataType:=ppPasteMetafile).Select
' newPowerPoint.ActiveWindow.Selection.ShapeRange.Left = 15
' newPowerPoint.ActiveWindow.Selection.ShapeRange.Top = 125
' activeSlide.Shapes(2).Width = 200
' activeSlide.Shapes(2).Left = 505
'Next ByI
For Each oTextBox In ActiveSheet.TextBoxes
'Add a new slide where we will paste the chart
newPowerPoint.ActivePresentation.Slides.Add newPowerPoint.ActivePresentation.Slides.Count + 1, ppLayoutText
newPowerPoint.ActiveWindow.View.GotoSlide newPowerPoint.ActivePresentation.Slides.Count
Set activeSlide = newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Slides.Count)
'Copy the chart and paste it into the PowerPoint as a Metafile Picture
oTextBox.Select
oTextBox.Copy
activeSlide.Shapes.PasteSpecial(DataType:=ppPasteMetafile).Select
'Set the title of the slide the same as the title of the chart
'activeSlide.Shapes(1).TextFrame.TextRange.Text = cht.Chart.ChartTitle.Text
'Adjust the positioning of the Chart on Powerpoint Slide
newPowerPoint.ActiveWindow.Selection.ShapeRange.Left = 15
newPowerPoint.ActiveWindow.Selection.ShapeRange.Top = 125
activeSlide.Shapes(2).Width = 200
activeSlide.Shapes(2).Left = 505
Next
AppActivate ("Microsoft PowerPoint")
Set activeSlide = Nothing
Set newPowerPoint = Nothing
End Sub