aamailhot
aamailhot

Reputation: 133

Set PPT Font to 'Body' Type

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.

Upvotes: 0

Views: 962

Answers (2)

Fred B
Fred B

Reputation: 29

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;
                    

Upvotes: 0

Steve Rindsberg
Steve Rindsberg

Reputation: 14809

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"

Upvotes: 5

Related Questions