Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. Option Explicit
  2.  
  3. Dim myFile, Fileselected As String, Path As String, objPPT As Object
  4. Dim ppApp As PowerPoint.Application
  5. Dim ppPres As PowerPoint.Presentation
  6.  
  7. Dim activeSlide As PowerPoint.Slide
  8.  
  9. Sub Generate_PPTs()
  10. Dim cht As ChartObject
  11. Dim sht As Worksheet
  12. Dim sld As Object
  13. Dim shp As Object
  14. Dim chname As String
  15. Dim schname As String
  16.  
  17.  
  18. Set myFile = Application.FileDialog(msoFileDialogOpen)
  19. With myFile
  20. .Title = "Choose Template PPT File."
  21. .AllowMultiSelect = False
  22.  
  23. If .Show <> -1 Then
  24. Exit Sub
  25. End If
  26. Fileselected = .SelectedItems(1)
  27. End With
  28. Path = Fileselected
  29.  
  30. Dim i As Integer
  31.  
  32. Set ppApp = New PowerPoint.Application
  33. i = 1
  34.  
  35. ppApp.Presentations.Open Filename:=Path, ReadOnly:=msoFalse
  36. Set ppPres = ppApp.Presentations.Item(i)
  37.  
  38. ' for debug
  39. Debug.Print ppPres.Name
  40.  
  41. Set activeSlide = ppPres.Slides(i)
  42. Set sht = ActiveSheet
  43. sht.Activate
  44. Application.EnableEvents = True
  45. For Each sht In ActiveWorkbook.Worksheets
  46.  
  47. For Each cht In sht.ChartObjects
  48. cht.Activate
  49. chname = cht.Name
  50. cht.Select
  51. ActiveChart.ChartArea.Copy
  52.  
  53.  
  54. For Each sld In ppPres.Slides
  55.  
  56. For Each shp In sld.Shapes
  57. schname = shp.Name
  58. If schname = chname Then
  59. Debug.Print chname
  60.  
  61. activeSlide.Shapes.Paste.Select
  62.  
  63. End If
  64. Next
  65.  
  66. Next
  67. Next
  68. Next
  69.  
  70.  
  71.  
  72.  
  73. Application.ScreenUpdating = True
  74. Set ppPres = Nothing
  75. Set ppApp = Nothing
  76.  
  77. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement