PowerPoint New Slide thumbnails fail to refresh after VBA code to hide elements

Hi experts

I have a PowerPoint presentation where via VBA I am applying different colour schemes and hiding shapes on various slide masters in the presentation.

That all works well. My issue, however, is that when I go to insert a new slide via the New Slide button on the ribbon, the thumbnails have not refreshed. The only way I can get them to refresh is to close the presentation and re-open it. Not desirable. Any ideas how to resolve?
Fi69Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
Have you got any code which could stop the refreshing? What version of PowerPoint are you using?

It might help if you post the code.
0
Fi69Author Commented:
Using PowerPoint 2010.

My code below.

Is there any way I can update PowerPoint's Home tab on the ribbon?

Sub ChangeTheme(strThemeName As String)

    Dim oDesign As Design
    Dim oCl As CustomLayout
    Dim lngLayoutCount As Long
    Dim i As Integer
    Dim oShp As Shape
    Dim strLogoName As String
    Dim strPicName As String
    Dim strFilePath As String
    
    Set ThisPres = ActivePresentation
        
    'Iterate through all the available layouts and show hide images
    For Each oDesign In ThisPres.Designs
        For Each oShp In oDesign.SlideMaster.Shapes
            If oShp.Name = "Gas" And strThemeName <> "Gas" Then oShp.Visible = msoFalse
            If oShp.Name = "Electricity" And strThemeName <> "Electricity" Then oShp.Visible = msoFalse
            If oShp.Name = "Corporate" And strThemeName <> "Corporate" Then oShp.Visible = msoFalse
            If oShp.Name = strThemeName Then oShp.Visible = msoTrue
        Next oShp
        lngLayoutCount = oDesign.SlideMaster.CustomLayouts.Count
        For i = 1 To lngLayoutCount
            Set oCl = oDesign.SlideMaster.CustomLayouts(i)
            For Each oShp In oCl.Shapes
                If oShp.Name = "Gas" And strThemeName <> "Gas" Then oShp.Visible = msoFalse
                If oShp.Name = "Electricity" And strThemeName <> "Electricity" Then oShp.Visible = msoFalse
                If oShp.Name = "Corporate" And strThemeName <> "Corporate" Then oShp.Visible = msoFalse
                If oShp.Name = strThemeName Then oShp.Visible = msoTrue
                If oCl.Name = "Title Slide Coloured" Or oCl.Name = "Video Link Coloured" Then
                    If oShp.Type = msoPlaceholder Then
                        If strThemeName = "Corporate" Then
                            oShp.TextFrame.TextRange.Font.Color.ObjectThemeColor = msoThemeColorLight1
                        Else
                            oShp.TextFrame.TextRange.Font.Color.ObjectThemeColor = msoThemeColorDark1
                        End If
                    End If
                End If
            Next oShp
        Next
    Next
    
    ApplyColorScheme strThemeName
End Sub
Sub ApplyColorScheme(strThemeColor As String)

    On Error GoTo ErrHandler
    
    Dim oDesign As Design
    Dim check As Boolean
    Dim flname As String
    
    Set ThisPres = ActivePresentation
    
    If strThemeColor = "Gas" Then
        flname = "C:\Users\" & Environ("USERNAME") & "\AppData\Roaming\Microsoft\Templates\Document Themes\Theme Colors\Gas.xml"
    Else
        flname = "C:\Users\" & Environ("USERNAME") & "\AppData\Roaming\Microsoft\Templates\Document Themes\Theme Colors\Corporate.xml"
    End If
    
    check = FileExist(flname)
    If check = False Then CreateSaveNewColorTheme flname, strThemeColor
        
    'Iterate through all the available layouts and show hide images
    For Each oDesign In ThisPres.Designs
        oDesign.SlideMaster.theme.ThemeColorScheme.Load (flname)
    Next
    
    
    Exit Sub

ErrHandler:
    Exit Sub

End Sub



Sub CreateSaveNewColorTheme(strFile As String, ThemeName As String)

    Dim tTheme As OfficeTheme
    Dim tcsThemeColorScheme As ThemeColorScheme
     
    If ThemeName = "IMO Corporate" Then
        'corporate color theme
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeDark1).RGB = RGB(67, 82, 90) 'grey text
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeLight1).RGB = RGB(255, 255, 255) 'white
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeDark2).RGB = RGB(0, 173, 208) 'blue
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeLight2).RGB = RGB(204, 239, 246) 'light banding blue
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeAccent1).RGB = RGB(0, 173, 208) 'blue
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeAccent2).RGB = RGB(217, 83, 30)
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeAccent3).RGB = RGB(93, 151, 50)
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeAccent4).RGB = RGB(128, 90, 137)
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeAccent5).RGB = RGB(250, 166, 26)
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeAccent6).RGB = RGB(178, 187, 28) 'green
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeHyperlink).RGB = RGB(174, 188, 195)
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeFollowedHyperlink).RGB = RGB(179, 122, 181)
    Else
        'Gas colour theme
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeDark1).RGB = RGB(67, 82, 90) 'grey
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeLight1).RGB = RGB(255, 255, 255) 'white
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeDark2).RGB = RGB(67, 82, 90) 'grey
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeLight2).RGB = RGB(216, 221, 141) 'light banding green
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeAccent1).RGB = RGB(178, 187, 28) 'green
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeAccent2).RGB = RGB(217, 83, 30)
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeAccent3).RGB = RGB(93, 151, 50)
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeAccent4).RGB = RGB(128, 90, 137)
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeAccent5).RGB = RGB(250, 166, 26)
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeAccent6).RGB = RGB(0, 173, 208) 'blue
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeHyperlink).RGB = RGB(174, 188, 195)
        ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeFollowedHyperlink).RGB = RGB(179, 122, 181)
    End If
    ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Save (strFile)
     
End Sub
Sub CreateSaveNewColorThemeIMOGas(strFile As String)

    Dim tTheme As OfficeTheme
    Dim tcsThemeColorScheme As ThemeColorScheme
          
    ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeDark1).RGB = RGB(67, 82, 90)
    ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeLight1).RGB = RGB(255, 255, 255)
    
    ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeDark2).RGB = RGB(0, 173, 208) 'header row
    ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeLight2).RGB = RGB(204, 239, 246) 'light banding
    
    
    ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeAccent1).RGB = RGB(0, 173, 208)
    ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeAccent2).RGB = RGB(217, 83, 30)
    ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeAccent3).RGB = RGB(93, 151, 50)
    ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeAccent4).RGB = RGB(128, 90, 137)
    ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeAccent5).RGB = RGB(250, 166, 26)
    ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeAccent6).RGB = RGB(178, 187, 28)
    ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeHyperlink).RGB = RGB(0, 127, 179)
    ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Colors(msoThemeFollowedHyperlink).RGB = RGB(179, 122, 181)
    
    ActivePresentation.Designs(1).SlideMaster.theme.ThemeColorScheme.Save (strFile)
     
End Sub

Function FileExist(strFile As String) As Boolean
On Error GoTo Err_Handler
 
    FileExist = False
    If Len(Dir(strFile)) > 0 Then
        FileExist = True
    End If
 
Exit_Err_Handler:
    Exit Function
 
Err_Handler:
    MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: FileExist" & vbCrLf & _
           "Error Description: " & Err.description, vbCritical, "An Error has Occured!"
    GoTo Exit_Err_Handler
End Function

Open in new window

0
JSRWilsonCommented:
This is going to sound like black magic (it probably is).

I had a similar problem with a client recently and "jiggling" a shape on the master updated the ribbon!

Code example

ActivePresentation.Designs(1).SlideMaster.Shapes(1).Left = ActivePresentation.Designs(1).SlideMaster.Shapes(1).Left + 1
ActivePresentation.Designs(1).SlideMaster.Shapes(1).Left = ActivePresentation.Designs(1).SlideMaster.Shapes(1).Left - 1
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fi69Author Commented:
Hi JSR

Woooohoooo I love your black magic. Worked a treat thank you. I had to loop through all the designs to get them all to refresh.

Thanks you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.