Reputation: 407
How can I format textbox? Because now it is using the last format (no bold and size 20), but I need to have a Title with different format (bold and size 30). I found that I can do this with richtextbox, but I don´t know how to add richtextbox to the slides.
PowerPoint.Shape textBox = activeSlide.Shapes.AddTextbox( Office.MsoTextOrientation.msoTextOrientationHorizontal, 50, 50, 600, 500);
textBox.TextFrame.TextRange.Font.Bold = MsoTriState.msoTrue;
textBox.TextFrame.TextRange.Font.Size = 30;
textBox.TextFrame.TextRange.InsertAfter("This is Title with font size 30 and bold.");
textBox.TextFrame.TextRange.Font.Bold = MsoTriState.msoFalse;
textBox.TextFrame.TextRange.Font.Size = 20;
textBox.TextFrame.TextRange.InsertAfter("This is normal text with font size 20 and no bold.");
Upvotes: 0
Views: 3087
Reputation: 2500
Check out this link. It shows you how.
http://msdn.microsoft.com/en-us/library/jj159403(v=office.14).aspx
EDIT: So you asked how to add a richtextbox:
Dim rtfBox As RichTextBox = New RichTextBox
rtfBox.Paste()
Then you can edit rtfBox to the format that you wish. Simple as that. Or you can make a template and use the Apply Template Method.
Here are some other links that might help you. They mention editing the slides and changing the font:
Accessing Slide StackFlow Question
Upvotes: 1
Reputation: 14809
Here's an example of how you'd do it in VBA. You can use the length of the different text strings and .Characters to return a text range that you format however you like w/o affecting the other text.
Dim oSh As Shape
Dim sBoldText As String
Dim sNotBoldText As String
sBoldText = "This is the title, 30 and bold."
sNotBoldText = " This is the other text, 20 and not bold."
Set oSh = ActivePresentation.Slides(1).Shapes.AddTextbox(msoTextOrientationHorizontal, 100, 100, 500, 100)
oSh.TextFrame.TextRange.Text = sBoldText & sNotBoldText
With oSh.TextFrame.TextRange.Characters(1, Len(sBoldText))
.Font.Bold = True
.Font.Size = 30
End With
With oSh.TextFrame.TextRange.Characters(Len(sBoldText) + 1)
.Font.Bold = False
.Font.Size = 20
End With
Upvotes: 1