Thanks for the help. I'm not sure if you have seen my last 'editing', but it is partially working --> all numbers above 5 will give the abovementioned error "... valid range of 1 to 5"
When the numeric value in cell B6 is 0 it gives the same error but then ".. valid range of 1 to 50"
Nevermind, I got it to work. I understand the problem --> The PPT itself had less than the number displayed in cell B6 (duhhhhh).
This is the properly working code for any of you interested:
Sub ChartToPresentation()
Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim shp As String
Dim newShape As PowerPoint.ShapeRange
Dim rng As Range
Dim cell As Range
Dim x As Integer
x = Worksheets("VIVA GRAPH").Range("PPTSlide")
' Make sure a chart is selected
If ActiveChart Is Nothing Then
MsgBox "Please select a chart and try again.", vbExclamation, _
"No Chart Selected"
Else
' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
' Reference active slide
Set PPSlide = PPPres.Slides(Worksheets("VIVA GRAPH").Range("B6").Value)
' Copy chart as a picture
ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, _
Format:=xlPicture
' Paste chart
Set newShape = PPSlide.Shapes.Paste
'Resize chart'
With newShape
.IncrementLeft 400
.IncrementTop 250
.ScaleWidth 0.87, msoFalse, msoScaleFromTopLeft
.ScaleHeight 0.87, msoFalse, msoScaleFromTopLeft
End With
' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End If
End Sub
Thanks for sharing your expertise Jo(h)n, really appreciate it.