Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Dim myFile, Fileselected As String, Path As String, objPPT As Object
- Dim ppApp As PowerPoint.Application
- Dim ppPres As PowerPoint.Presentation
- Dim activeSlide As PowerPoint.Slide
- Sub Generate_PPTs()
- Dim cht As ChartObject
- Dim sht As Worksheet
- Dim sld As Object
- Dim shp As Object
- Dim chname As String
- Dim schname As String
- Set myFile = Application.FileDialog(msoFileDialogOpen)
- With myFile
- .Title = "Choose Template PPT File."
- .AllowMultiSelect = False
- If .Show <> -1 Then
- Exit Sub
- End If
- Fileselected = .SelectedItems(1)
- End With
- Path = Fileselected
- Dim i As Integer
- Set ppApp = New PowerPoint.Application
- i = 1
- ppApp.Presentations.Open Filename:=Path, ReadOnly:=msoFalse
- Set ppPres = ppApp.Presentations.Item(i)
- ' for debug
- Debug.Print ppPres.Name
- Set activeSlide = ppPres.Slides(i)
- Set sht = ActiveSheet
- sht.Activate
- Application.EnableEvents = True
- For Each sht In ActiveWorkbook.Worksheets
- For Each cht In sht.ChartObjects
- cht.Activate
- chname = cht.Name
- cht.Select
- ActiveChart.ChartArea.Copy
- For Each sld In ppPres.Slides
- For Each shp In sld.Shapes
- schname = shp.Name
- If schname = chname Then
- Debug.Print chname
- activeSlide.Shapes.Paste.Select
- End If
- Next
- Next
- Next
- Next
- Application.ScreenUpdating = True
- Set ppPres = Nothing
- Set ppApp = Nothing
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement