0

I am not able to paste the entirety of my code, but the crux is that I have a textbox in PPT 2013, myTb, that I have (programmatically) pasted some text into. I now want to perform the following two actions:

  1. See if the original text was the PPT 'body default' font (e.g. 'Calibri (body)' vs. 'Calibri' in the MS Ribbon)
  2. If it was the body default, set the new text to also be the body default.

I can't seem to figure either part out, even though I have experimented with reading/writing from/to most of the Shape.TextFrame[n].TextRange.Font.Name... fields. I also had two confounding points to ask about, regarding the Shape.TextFrame.TextRange.Font.NameComplexScript field:

  1. This field does not seem to be a 'complete' indicator of body-default vs non-body-default font. The reason is that if this textbox is originally the body-default ('Calibri (body)'), it will read '+mn-cs', but then I can change the font to the non-default variant ('Calibri'), and it still reads '+mn-cs'.
  2. I then proceed to change the textbox to an entirely different font, which changes this field to the font's name as expected. However, if I then change back to the body-default font (or any other font, for that matter), this field remains on the previous font's name.
aamailhot
  • 113
  • 2
  • 8

2 Answers2

4

To set the font to the body or heading font, you need to use a weird bit of syntax:

{object}.Font.Name = "+" + FontType + "-" + FontLang

Where:

FontType is "mj" or "mn" for Major (headings) or Minor (body) respectively.

FontLang is "lt", "cs" or "ea" for Latin, Complex Scripts or East Asian

For example to set the font to the theme's body text font for Latin text:

ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Font.Name = "+mn-lt"
Steve Rindsberg
  • 14,442
  • 1
  • 29
  • 34
  • How does this Font.Name string determine the difference between 'Calibri' and 'Calibri (body)' though? As I described above, both of these font types show up as 'mn' for the FontType in this string, even though they are distinctly different from one-another. – aamailhot Nov 01 '17 at 20:30
  • I think we'd need to see a more detailed description of how you made the changes you describe in your original post. Via code or manually and either way, exactly how? – Steve Rindsberg Nov 02 '17 at 00:56
  • I know this is old, but the above worked for me. I wanted to set the font to Georgia which is the main PowerPoint theme that I had selected. If I did Font.Name = "Georgia" then it hard-coded this as the font. But using the above set it to body font as desired. Thanks – Dean Jul 19 '19 at 18:47
  • @Dean And I'm late to the party too. But in case it helps, PPT has themes, which include specs for fonts, colors and a few other bits. You can think of these as lookup-tables. Specifiying a theme font (ie, heading or body) tells PPT "Go to the font theme table, look up the name of the body font, use that". When you change the font theme, any font that's been assigned body or heading THEME fonts will change accordingly. When you tell PPT "Make this text Georgia", the font is no longer connected to the theme, and stays Georgia even when the theme changes. Each has its uses. – Steve Rindsberg Jan 18 '21 at 16:11
0

A bit late to the party, but I found this in case anyone needs it.

Edit: This is C# code, using the Interop PowerPoint namespace.

string headingsThemeFont = Globals.ThisAddIn.Application.ActivePresentation.SlideMaster.Theme.ThemeFontScheme.MajorFont.Item(MsoFontLanguageIndex.msoThemeLatin).Name;
                   
string bodyThemeFont = Globals.ThisAddIn.Application.ActivePresentation.SlideMaster.Theme.ThemeFontScheme.MinorFont.Item(MsoFontLanguageIndex.msoThemeLatin).Name;
                    
Fred B
  • 29
  • 8
  • Since this thread's tagged "VBA", your answer doesn't exactly fit, but it'll no doubt be useful to someone who wants to solve the problem in (I'm guessing) VBA.NET. Please edit your comment to point out that it's a solution for {whatever.language} – Steve Rindsberg Jan 18 '21 at 16:06
  • 1
    You're right Steve, thanks for pointing that out. I've edited my answer. – Fred B Jan 21 '21 at 11:29
  • Warning - this doesn't (always?) work for other scripts, i.e. not Latin. I have a template that has defined theme fonts for Latin, Asian and Arabic characters, but when I inspect the SlideMaster.Theme.ThemeFontScheme.MinorFont.Item(x).Name for x other than msoThemeLatin, the result is an empty string. – Jacek Kołodziejek Dec 13 '21 at 18:47