How to detect Theme fonts in Powerpoint 2007 VBA?

Does anyone know how to detect the use of Theme fonts in Powerpoint 2007 slide objects using VBA? If one looks at Shape.TextFrame.TextRange.Font.Name the font name appears as simple name (ex: "Arial") whether or not the font was assigned as a fixed name or a Theme name (subject to change with the document theme). I don't see any other property in the Object Model that would flag the name as tied to a theme (such as ObjectThemeColor for colors).

Thanks!

13.10.2009 21:43:39
2 ОТВЕТА
РЕШЕНИЕ

There is no direct method (that I know of), however you can check with an If/Then:

Sub checkthemeFont()
    Dim s As Shape
    Set s = ActivePresentation.Slides(1).Shapes(1)
    Dim f As Font
    Set f = s.TextFrame.TextRange.Font

    Dim themeFonts As themeFonts
    Dim majorFont As ThemeFont

    Set themeFonts = ActivePresentation.SlideMaster.Theme.ThemeFontScheme.MajorFont
    Set majorFont = themeFonts(msoThemeLatin)

    If f.Name = majorFont Then
        Debug.Print f.Name
    End If
End Sub
1
14.10.2009 04:02:27
Thanks Otaku for the reply but I think this only tells you whether the font name matches the Theme name, not whether the font of this shape is controlled by the theme setting. You could see this in the GUI by selecting the text, right clicking and selecting one of the top 2 fonts in the "Theme Fonts" section (The theme Headings and Body fonts). Then add another shape but select the same font name from the list below (the "All Fonts" section). The font name appears the same for both objects. Change the Theme and you'll see the first shape's font change but not the second.
Sam Russo 14.10.2009 13:47:01
Gotcha. Yeah, that is a tough one. The only thing I was able to find was the opposite of what you need, which is how to set the theme fonts (pptfaq.com/FAQ00957.htm). Getting them from the object as a property of the object doesn't appear to have any documentation.
Todd Main 14.10.2009 16:42:19
Yes, I found that too but I've never been able to catch font names like "+mj-It" as Steve mentions in the article, just plain vanilla font names...
Sam Russo 14.10.2009 17:27:49
Today, to my surprise I'm stepping thru some code and I did in fact just now get the elusive theme font name "+mn-lt" for a TextRange.Font.Name. I don't think it is consistent - nearly all other times I've only seen full names like "Arial". I'll just be ready for both now. And I think the way to drop the theme reference is always to set the font name with the full name.
Sam Russo 29.10.2009 14:53:12
I realise this is a very old question, but one approach might be to store the current Major/Minor theme fonts, change them, check if the object in question's font has changed, and then change them back...
tobriand 23.09.2014 10:22:33

Thanks to the idea from @tobriand here is an implementation that reports if any placeholders are set to hard coded fonts rather than those from the theme:

Option Explicit

' =================================================================================
' PowerPoint VBA macro to check if all text-supporting placeholders are set
' to use one of the two theme fonts or are "hard coded".
' Checks all slide masters in the active presentation.
' Author : Jamie Garroch
' Company : BrightCarbon Ltd. (https://brightcarbon.com/)
' Date : 05MAR2020
' =================================================================================
Public Sub CheckMastersUseThemeFonts()
  Dim oDes As Design
  Dim oCL As CustomLayout
  Dim oShp As Shape
  Dim tMinor As String, tMajor As String
  Dim bFound As Boolean
  Dim lMasters, lLayouts, lPlaceholders

  ' If you use Arial, change this to any font not used in your template
  Const TEMP_FONT = "Arial"

  For Each oDes In ActivePresentation.Designs
    lMasters = lMasters + 1

    ' Save the current theme fonts before changing them
    With oDes.SlideMaster.Theme.ThemeFontScheme
      tMajor = .MajorFont(msoThemeLatin).Name
      tMinor = .MinorFont(msoThemeLatin).Name
      .MajorFont(msoThemeLatin).Name = TEMP_FONT
      .MinorFont(msoThemeLatin).Name = TEMP_FONT
    End With

    ' Check if any are not set to the temporary font, indicating hard coding
    For Each oCL In oDes.SlideMaster.CustomLayouts
      lLayouts = lLayouts + 1
      For Each oShp In oCL.Shapes
        If oShp.Type = msoPlaceholder Then lPlaceholders = lPlaceholders + 1
        If oShp.HasTextFrame Then
          Select Case oShp.TextFrame.TextRange.Font.Name
            Case "Arial"
            Case Else
              bFound = True
              Debug.Print oShp.TextFrame.TextRange.Font.Name, oDes.Name, oCL.Name, oShp.Name
          End Select
        End If
      Next
    Next

    ' Restore the original fonts
    With oDes.SlideMaster.Theme.ThemeFontScheme
      .MajorFont(msoThemeLatin).Name = tMajor
      .MinorFont(msoThemeLatin).Name = tMinor
    End With

  Next

  If bFound Then
    MsgBox "Some placeholders are not set to use the theme fonts. Press Alt+F11 to see them in the Immediate pane.", vbCritical + vbOKOnly, "BrightSlide - Master Theme Fonts"
  Else
    MsgBox "All placeholders are set to use the theme fonts.", vbInformation + vbOKOnly, "BrightSlide - Master Theme Fonts"
  End If

  ' Provide some stats on what was checked
  Debug.Print "Masters: " & lMasters
  Debug.Print "Layouts: " & lLayouts
  Debug.Print "Placeholders: " & lPlaceholders
End Sub
0
5.03.2020 22:02:14