I am creating a powerpoint in VBA, but there are a lot of slides in it.
I was thinking I could create a macro that calls a lot of subroutines. Within those subroutines, the actual "slide code" would run. However, I have only created powerpoints where all of the code was in the same subroutine.
I took a shot at it and the below code creates what I want.
My question is, Public and Private variables and the use of "Dim". Would it be bad code if I put all of this in one module and use a bunch of subroutines? Or should I separate over modules? I would prefer to do that so I do not have to define each variable such as
ppPres, but open to any suggestions. I am mainly looking for ideas on how to set this up.
Public ppApp As PowerPoint.Application Public ppPres As PowerPoint.Presentation Public ppSlide As PowerPoint.Slide sub CreatePres() Dim ppTextbox As PowerPoint.Shape Dim slidesCount As Long Set ppApp = New PowerPoint.Application ppApp.Visible = True ppApp.Activate Set ppPres = ppApp.Presentations.Add slidesCount = ppPres.Slides.Count Set ppSlide = ppPres.Slides.Add(slidesCount + 1, ppLayoutTitle) ppSlide.Shapes(1).TextFrame.TextRange.Text = "Hello world" ppSlide.Shapes(2).TextFrame.TextRange.Text = Date slidesCount = slidesCount + 1 Call slide2(slidesCount) End Sub Sub slide2(i As Integer) 'Insert CPR speeds Chart and Table --- slide 2 Set ppSlide = ppPres.Slides.Add(i+ 1, ppLayoutBlank) ppSlide.Select Worksheets("Sheet1").Activate ActiveSheet.Range(Cells(1, 4), Cells(2, 9)).Copy ppSlide.Shapes.Paste.Select ppSlide.Shapes(1).Width = _ (ppPres.PageSetup.SlideWidth / 2) ppSlide.Shapes(1).Left = _ (ppPres.PageSetup.SlideWidth / 4) ppSlide.Shapes(1).Top = _ 4 * (ppPres.PageSetup.SlideHeight / 5) ActiveSheet.ChartObjects("Chart1").Activate ActiveChart.ChartArea.Copy ppSlide.Shapes.Paste.Select ppSlide.Shapes(2).Height = _ 3 * (ppPres.PageSetup.SlideHeight / 5) ppSlide.Shapes(2).Width = _ 5 * (ppPres.PageSetup.SlideWidth / 7) ppSlide.Shapes(2).Left = _ (ppPres.PageSetup.SlideWidth / 7) ppSlide.Shapes(2).Top = _ (ppPres.PageSetup.SlideHeight / 10) End sub