VBA Runtime Error 462 - where does the missing object variable go?

CEMOL

New Member
Joined
Mar 6, 2018
Messages
3
Hello everybody,

I read a lot about the Runtime Error "462". And concluded that the my problem is that somewhere in my code I haven't used the appropriate Object variable(s).

I'm very new to VBA and have been searching for 2 whole days now.

Hopefully someone can help me.

My code:
Rich (BB code):
Sub EXPORTTOPPT2()
    Dim ppt As PowerPoint.Application
    Dim pptPres As PowerPoint.Presentation
    Dim pptSld As PowerPoint.Slide
    Dim pptCL As PowerPoint.CustomLayout
    Dim pptShp As PowerPoint.shape
    Dim shp As shape
    Dim ws As Worksheet
    Dim LosGraf As Long
    
                                                   
    'open PPT and remove slides already in PPT
    Set ppt = CreateObject("PowerPoint.Application")
    ppt.Visible = msoTrue
    Set pptPres = ppt.Presentations.Open("Y:\LOBE\Public\Planningsafdeling\VBA\PPT\VM Project.pptm")
    ppt.Run "VM Project.pptm!DeleteSlides.DeleteSlides" '--> goes to Macro in PPT
                                            
            
    'Layout
    For Each pptCL In pptPres.SlideMaster.CustomLayouts
        If pptCL.Name = "Title and Content" Then Exit For
    Next pptCL
   
   
    'Transfer all shapes from Excel to PPT
    For Each ws In ActiveWorkbook.Worksheets
        For LosGraf = 1 To ws.Shapes.Count
            Set pptSld = pptPres.Slides.AddSlide(pptPres.Slides.Count + 1, pptCL)
            pptSld.Select
            
           
            For Each pptShp In pptSld.Shapes.Placeholders
               If pptShp.PlaceholderFormat.Type = ppPlaceholderObject Then Exit For
            Next pptShp
           
            Set shp = ws.Shapes(LosGraf)
            shp.Copy
            ppt.Activate
            pptShp.Select
            ppt.Windows(1).View.Paste
        Next LosGraf
    Next ws
    
    
End Sub

The error always occurs in the last piece:
Rich (BB code):
For Each pptShp In pptSld.Shapes.Placeholders
               If pptShp.PlaceholderFormat.Type = ppPlaceholderObject Then Exit For
            Next pptShp
           
            Set shp = ws.Shapes(LosGraf)
            shp.Copy
            ppt.Activate
            pptShp.Select
            ppt.Windows(1).View.Paste
        Next LosGraf
    Next ws

Does somebody know a solution?
 
Last edited by a moderator:

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
dont put : Next [var]

just put: NEXT
next doesnt need the variable in it. Cause if you get it wrong...ERROR. (like you have)

and I see NEXT, but no FOR above it.
 
Last edited:
Upvote 0
Which line of code causes the error?
 
Upvote 0
dont put : Next [var]

just put: NEXT
next doesnt need the variable in it. Cause if you get it wrong...ERROR. (like you have)

and I see NEXT, but no FOR above it.


I tried loosing the variables after next but that didn't work. I checked The Next/For and I think they are all there? Where do you think I went wrong?
 
Upvote 0
Which line of code causes the error?

Most of the times I get the error on the line:
Code:
For Each pptShp In pptSld.Shapes.Placeholders

But sometimes I get it a little bit further on on:
Code:
ppt.Activate
Or
Code:
 pptShp.Select
 
Upvote 0
if the error is on: pptSld.Shapes.Placeholders
use the debuging immediate window (ctl-G) to check the count
type: ?pptSld.Shapes.count
to see if there ARE some shapes

you can also check if an object exists:
?ppt is nothing
if true then the object was never created because the creation source didnt exist.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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