Hello,
I am using following VBA to transfer data from excel to PowerPoint.
I am getting error on this line:
Set PPslide = PPpres.Slides(1)
When I debug it says:
-Object variable or with block not set
And:
PPslide = Nothink
What I do wrong?
I am using following VBA to transfer data from excel to PowerPoint.
I am getting error on this line:
Set PPslide = PPpres.Slides(1)
When I debug it says:
-Object variable or with block not set
And:
PPslide = Nothink
What I do wrong?
VBA Code:
Private Sub CommandButton2_Click()
Dim PP As PowerPoint.Application
Dim PPpres As PowerPoint.Presentation
Dim PPslide As Object
Dim PpShape As PowerPoint.Shape
Dim SlideTitle As String
Dim SlideNum As Integer
Dim WSrow As Long
Dim Sh As Shape
Dim Rng As Range
Dim myShape As Object
'Open PowerPoint and create new presentation
Set PP = GetObject(class, "PowerPoint.Application")
PP.Visible = True
PP.Presentations.Open Filename:="C:\Users\Mac\Desktop\test\PPT.pptx"
'Specify the chart to copy and copy it
For Each WS In Worksheets
If (WS.Name) <> "EOS" Then
ThisWorkbook.Worksheets(WS.Name).Activate
ThisWorkbook.ActiveSheet.UsedRange.CopyPicture
'pSlide.Shapes.Paste
'Copy Range from Excel
Set Rng = ThisWorkbook.ActiveSheet.Range("A1:A5")
'Copy Excel Range
Rng.Copy
'Set PPslide = PPpres.Slides.Add(5, 33)
PP.ActiveWindow.View.GotoSlide (1)
Set PPslide = PPpres.Slides(1)
'Paste to PowerPoint and position
PPslide.Shapes.PasteSpecial DataType:=2 '2 = ppPasteEnhancedMetafile
Set myShape = PPslide.Shapes(PPslide.Shapes.Count)
'Set position:
myShape.Left = 66
myShape.Top = 152
End If
Next
'Make PowerPoint Visible and Active
PP.Visible = True
PP.Activate
'Clear The Clipboard
Application.CutCopyMode = False
'enter code here
End Sub