1
votes

I am all new to powerpoint vba. All i want do is to write a little piece of code wich allows me to change the layout of my slide depending on a selection made by clicking a button.

The Problem with my code is that i get the runtimeerror 438.

Here is what i have:

Private Sub CommandButton1_Click() 'Klick Button 1'

ActivePresentation.Slides(10).Delete 
ActivePresentation.Slides(9).Delete 
ActivePresentation.Slides(8).Delete  

Dim x As Integer 
For x = 1 To 100
With ActivePresentation.Slides(x)
    If .CustomLayout = .CustomLayout(8) Then
    Set .CustomLayout = .CustomLayout(12)
    End If
End With
Next x
End Sub

EDIT: Error Description is: "object does not support this property or method"

I'd really appreciate any kind of help and constructive input.

EDIT II: I understand now that .CustomLayout returns a custom layout. But how can i set/change the Layout of a certrain slide? How do i need to adress it? Thank you very much

EDIT III: I still have no solution and i am really frustrated right now. You guys are my last chance for help I guess. So here again my code right now:

Dim x As Integer 
For x = 7 To 100
If ActivePresentation.Slides(x).CustomLayout =  ActivePresentation.Designs(1).SlideMaster.CustomLayouts(8) Then  ActivePresentation.Slides(x).CustomLayout =  ActivePresentation.Designs(1).SlideMaster.CustomLayouts(12) 
End If 
Next x

I still get the runtime error descriped above. How can i get rid of it and make my code work? Thank you very much!

1
Could you please also include the Error Description associated with this error, and the LOC that throws this error? - PaulFrancis
Of course! Since i am german, i get the Error Descriotion in german. Trying to translate as good as possible: "Object does not support this property or method" - Ruben
@Ruben what version of Office are you using? - razcor
@razcor I am using Powerpoint 2010 I now tried using the code you suggested. Unfortunately i still get the same Error Message - Ruben
@Ruben Your If block is wrong, I added a correct one editing my answer. - razcor

1 Answers

0
votes

CustomLayout is an object tha define a custom layout, in the interface they are:

enter image description here

In vba they can be accessed using the ActivePresentation.Designs.SlideMaster object.

Every Slide object can have, obviously, only 1 CustomLayout applied, and you can access it using the property CustomLayout.

So, if you want to change the slide 1 CustomLayout using the CustomLayout n. 3 you have to do:

ActivePresentation.Slides(1).CustomLayout = ActivePresentation.Designs(1).SlideMaster.CustomLayouts(3)

See : MSDN

Regarding your code, you MUST use Names in your If block comaprison, so:

If ActivePresentation.Slides(x).CustomLayout.Name =  ActivePresentation.Designs(1).SlideMaster.CustomLayouts(3).Name Then
    ActivePresentation.Slides(x).CustomLayout =  ActivePresentation.Designs(1).SlideMaster.CustomLayouts(7)
End If