none
All shapes is not found in Slide Master after ApplyTemplate in Powerpoint RRS feed

  • Question

  • Hi

    Our customer has two Powerpoint templates, one Standard (4:3) and one widescreen (16:9)
    We are trying to create a function to switch between the two, but has stuck with a strange problem.

    In the templates SlideMaster, we have a CustomLayout called Start on which there is two images with square dimensions.
    One is a colored figure and the other on is a logotype.
    In the Customlayout we have given them names.
    The logotype is called CUSLogosmal in the Standard template and CUSLogobred in the wide template.

    Also, the Customlayout has a distinguished name so that we can separate them between the templates.

    In the code we first get the name of the new template and the template Customlayout according to a choice in the UI, like this:

    tmplPres = pwtApp.Presentations.Open(sizeTemplate, False, True, False)
    newPresDesign = tmplPres.Designs.Item(0).Name
    tmplPres.Close()

    sizeTemplate is the full name of the template with "the other" dimensions.

    We then applies the new template on the active presentation, and adjust the size to the new size, like this,

    pres.ApplyTemplate(sizeTemplate)
    pres.PageSetup.SlideWidth = newSize
    Next step is to delete all CustomLayouts in the active presentation that have another name than the one from the new template, like this:
    For Each presDesign In pres.Designs
        If presDesign.Name <> newPresDesign Then
    	presDesign.Delete()
        End If
    Next

    At this time the presentation consist of the new SlideMaster applied from the new template.
    What we realized here was that there where some duplicate images on the Start Customlayout, and that their dimensions where changed and not squared anymore.

    We created a cleaning loop to delete all shapes with names that ended with the name we don't want, like this:

    Dim chkName As String
    If newSize = 720 Then
        chkName = "bred"
    Else
        chkName = "smal"
    End If
    
    For Each presLayout As PowerPoint.CustomLayout In presDesign.SlideMaster.CustomLayouts
        For Each shp In presLayout.Shapes
    	If shp.Name.StartsWith("CUS") Then
    	    If shp.Name.ToLower.EndsWith(chkName) Then
    		shp.Delete()
    	    End If
    	End If
        Next
    Next

    When we examine the processed presentation, we find a duplicate logotype with the name CUSLogosmal in the Customlayout.
    This image should have been deleted in the cleaning process.
    We have logged all existing images in the cleaning process, but the image CUSLogosmal is missing when we run the function, but exist when we later examine the resulting presentation.

    Anybody has a clue what is going on here?





    Best Regards Peter Karlström Midrange AB, Sweden

    Wednesday, March 4, 2020 10:35 AM