Reputation: 17783
Is there a way to create styles in PowerPoint VSTO to format text, something similar to what is possible with Word document:
// document is of type Microsoft.Office.Interop.Word.Document
Style sectionHeadingExt = document.Styles.Add("myStyle");
sectionHeadingExt.set_BaseStyle(SectionHeadingInt);
sectionHeadingExt.Font.Size = 14;
sectionHeadingExt.Font.Color = WdColor.wdColorBlack;
sectionHeadingExt.Font.Bold = (int)MsoTriState.msoFalse;
sectionHeadingExt.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceMultiple;
sectionHeadingExt.ParagraphFormat.LineSpacing = _application.LinesToPoints((float)1.11);
sectionHeadingExt.ParagraphFormat.SpaceBefore = 0;
sectionHeadingExt.ParagraphFormat.SpaceAfter = 0;
I need to create a custom ribbon tab, add a button there, and when that button is clicked I need to format the selected paragraph accordingly:
GetCurrentParagraph().set_Style("myStyle");
I did this in Word AddIn, but is it possible with PowerPoint? Also I can't see Styles/Change Styles options in PowerPoint (in Word they appear on Home tab).
Upvotes: 0
Views: 1860
Reputation: 3528
Word has a Styles feature; PowerPoint doesn't, so it's not possible to do this the same way you'd do it in Word.
You'll probably need to write code to pick up and store the various attributes that determine what a piece of text looks like (font name, size, bold/italic, line spacing, paragraph spacing, color etc) and code to apply the stored attributes to another piece of text.
(and re your followup comment) ... Yes.
Dim oRng As TextRange
' Is text selected? If so, work with it, else quit:
With ActiveWindow.Selection
If .Type = ppSelectionText Then
Set oRng = .TextRange
Else
Exit Sub
End If
End With ' Selection
With oRng
With .Font
.Bold = True
.Size = 24 ' point
' and so on
End With
End With ' oRng
Upvotes: 1