Excel to PowerPoint error ( Object variable or with block not set )

Akbarov

Active Member
Joined
Jun 30, 2018
Messages
347
Office Version
  1. 365
Platform
  1. Windows
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?

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
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
You never initialised the variable. Change this:

VBA Code:
PP.Presentations.Open Filename:="C:\Users\Mac\Desktop\test\PPT.pptx"

to this:

VBA Code:
Set PPpres = PP.Presentations.Open(Filename:="C:\Users\Mac\Desktop\test\PPT.pptx")
 
Upvote 0
Solution
You never initialised the variable. Change this:

VBA Code:
PP.Presentations.Open Filename:="C:\Users\Mac\Desktop\test\PPT.pptx"

to this:

VBA Code:
Set PPpres = PP.Presentations.Open(Filename:="C:\Users\Mac\Desktop\test\PPT.pptx")
Thank you very much :)
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top