Solved

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

Posted on 2014-09-23
4
810 Views
Last Modified: 2014-09-24
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?
0
Comment
Question by:Fi69
  • 2
4 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
Comment Utility
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
 

Author Comment

by:Fi69
Comment Utility
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
 
LVL 23

Accepted Solution

by:
JSRWilson earned 500 total points
Comment Utility
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
 

Author Comment

by:Fi69
Comment Utility
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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Setting the Scene PowerPoint is a creative tool in the right hands but it also includes a much underutilised programming dimension. In this beginner level article, we're going to show you some of some key elements of programming PowerPoint using th…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This video teaches viewers how to add simple and professional themes to their slides.
This video teaches viewers how to add transitions to their Slideshows and how to set up timing for the transitions.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now