Share via

Problems renaming slide template with VBA

Anonymous
2012-11-23T16:39:25+00:00

I have the following code to reset my template to a common master file (MR.potm). It works for most files, but not all.

I would note that if I manually rename the slide master away from 'IRL_BUR_Template' to something like xx then this code works fine which has me stumped.

I'm assuming that this line will do the same as a manual template rename (open VIEW / SLIDEMASTER / <right click RENAME> etc.: 

application.ActivePresentation.SlideMaster.Name = "xx"

Any help or comments greatly appreciated,

Thanks!

Sub Set_MgtRvw_Template()

    Dim strP, strF As String

    Debug.Print "---------------- " & Now()

    Debug.Print "---------------- Re-Setting Template Slide Master"

' Rename current template to enable new application of the same if the name is unchanged...

    application.ActivePresentation.SlideMaster.Name = "xx"

    DoEvents

'    Dim HasIRLBURTemplate As Boolean

' JUST GO AHEAD AND ADD THE CORRECT TEMPLATE (No Worries if Duplicate):

    strP = "C:\Documents and Settings\xxx\Application Data\Microsoft\Templates"

    strF = "MR.potm"

    strF = strP & strF

    application.ActivePresentation.ApplyTemplate (strF)

    application.ActivePresentation.ApplyTheme (strF)

    On Error Resume Next   ' Defer error handling.

    Err.Clear

' DELETE ALL BUT THE REQURED TEMPLATE (Duplicates start with n_xxxx and get deleted):

Do While Err.Number = 0

'    If Application.ActivePresentation.SlideMaster.Name <> "IRL_BUR_Template" Then

    If application.ActivePresentation.SlideMaster.Name <> "MR_IRL_Template" Then

        application.ActivePresentation.SlideMaster.Delete

'        MsgBox Err.Number & " !! " & Err.Description

    End If

Loop

' MAKE ALL SLIDE NUMBERS VISIBLE:

    application.ActivePresentation.PageSetup.FirstSlideNumber = 1

    For Each s In ActivePresentation.Slides

        s.ApplyTemplate (strF)

        s.DisplayMasterShapes = True

        s.HeadersFooters.Clear

        s.HeadersFooters.DisplayOnTitleSlide = True

        s.HeadersFooters.SlideNumber.Visible = True

        s.HeadersFooters.SlideNumber.Text = "Page : <#>"

    Next

    Debug.Print "---------------- "

End Sub

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-11-24T01:47:09+00:00

Hi,

Are you assuming that the presentation will have only one master?

http://skp.mvps.org/designs.htm

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2012-11-24T12:06:09+00:00

    Designs looks like a much better, more correct, way to update/replace my template.  I particularly like the .Load method in your reference article.  Thank you for pointing me to this. Time for me to explore my DESIGNS. Options... !

    Was this answer helpful?

    0 comments No comments