JSchroeder71
New Member
- Joined
- Jan 28, 2016
- Messages
- 25
I currently have an Excel Workbook that "semi-manually" generates a PowerPoint presentation. On each page of the spreadsheets I have a button that when clicked copies a range and/or text to a slide in PowerPoint (that it copies from a template). Currently I have to do that for each page in the spreadsheet. What I would like to do is have ONE button i can click to generate the Presentation from all the spreadsheets. I would like it to go through each spreadsheet that is NOT hidden and copy the specified range to a new slide, then move on to the next Spreadsheet and repeat until the end of the Workbook.
I am relatively new to VBA and have gotten this far with a lot of help from this community, I hope you can help me with this step. Current Code is below.
I should mention the way I am currently doing it I have to start with the last spreadsheet and work my way forward (5,4,3,2,1) so the presentation slides are in the correct order (1,2,3,4,5). I'm not sure how to correct this.
Thanks in advance,
John
I am relatively new to VBA and have gotten this far with a lot of help from this community, I hope you can help me with this step. Current Code is below.
Code:
Private Sub CommandButton6_Click()
' Initialize PowerPoint Object Library
Set PPApp = GetObject(, "Powerpoint.Application")
' Set PPApp = New PowerPoint.Application
PPApp.Visible = True
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
Set psheet = ActiveSheet
Set newslide = PPPres.Slides(10).Duplicate
'Set newslide = PPPres.Slides(11)
With newslide
.Shapes.Title.TextFrame.TextRange _
.Text = "2016 Renewal – " & ActiveSheet.Range("B41")
.Name = psheet.Range("B41")
.SlideShowTransition.Hidden = msoFalse
End With
SlideID = psheet.Range("B42")
' Copy the range as a picture
ActiveSheet.Range("A4:N33").CopyPicture Appearance:=xlScreen, Format:=xlPicture
' Paste the range and align it
Dim PPShapeRange As PowerPoint.ShapeRange
Set PPShapeRange = PPPres.Slides(SlideID).Shapes.Paste
With PPShapeRange
.Height = 324
.Align AlignCmd:=msoAlignCenters, RelativeTo:=True
.Align AlignCmd:=msoAlignMiddles, RelativeTo:=True
End With
' this is the message box to notify when done.
answer = MsgBox("The operation has completed successfully! Would you like to view the slide?", vbYesNo + vbQuestion, "Empty Sheet")
If answer = vbYes Then
Set PPApp = GetObject(, "PowerPoint.Application")
With PPApp
.Activate
.ActivePresentation.Slides(SlideID).Select
End With
Else
'do nothing
End If
End Sub
I should mention the way I am currently doing it I have to start with the last spreadsheet and work my way forward (5,4,3,2,1) so the presentation slides are in the correct order (1,2,3,4,5). I'm not sure how to correct this.
Thanks in advance,
John