Hey all,
The code below is extremely repetitive. Basically I'm just trying to create a new slide in PP between each set of dashes ("CAMPAIGN OVERVIEW", "OVERVIEW ANALYTICS"). I'm going to be writing the last two parts ('Add a new slide where we will paste the chart / ' Copy range from excel to current slide) over and over. I tried to create a separate sub-routine to call, which took in sheet name, range, and title as variables, but it failed because it didn't know what "newPowerPoint" was.
I hope it is clear what I'm looking for! Here is the code (incomplete - some other stuff at the end you don't need to worry about):
Sub create_pp()
'First we declare the variables we will be using
Dim newPowerPoint As PowerPoint.Application
Dim activeSlide As PowerPoint.Slide
Dim cht As Excel.ChartObject
Dim rng As Range
Dim x As Integer
Dim c As Integer
Dim rn As String
'Look for existing instance
On Error Resume Next
Set newPowerPoint = GetObject(, "PowerPoint.Application")
On Error GoTo 0
'Let's 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.Open Filename:="C:\Users\Ibotta\Desktop\Recap_Deck_V6_Master_Presentation.pptx"
End If
'Show the PowerPoint
newPowerPoint.Visible = True
'------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------
' CAMPAIGN OVERVIEW
Sheets("Overview_analytics_REP").Activate
x = 3
Do
Cells(1, x).Select
x = x + 1
Loop Until ActiveCell.Value = ""
ActiveCell.Offset(0, -1).Select
s = ActiveCell.Address
s = Right(s, Len(s) - 1)
s = Left(s, Len(s) - 2)
rn = "B2:$" & s & "$5"
'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 range from excel to current slide
Sheets("Overview_analytics_REP").Activate
ThisWorkbook.ActiveSheet.Range(rn).Copy
activeSlide.Shapes.PasteSpecial
Application.CutCopyMode = False
activeSlide.Shapes(1).TextFrame.TextRange.Text = "Campaign Overview"
'------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------
' OVERVIEW ANALYTICS
'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 range from excel to current slide
Sheets("Impres_Place_Redemp_REP").Activate
ThisWorkbook.ActiveSheet.Range("B2:B15").Copy
activeSlide.Shapes.PasteSpecial
Application.CutCopyMode = False
activeSlide.Shapes(1).TextFrame.TextRange.Text = "Overview Analytics"
'------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------
Bookmarks