How to create a custom textbox with set text, font type, font size, font colour in Powerpoint?

3.3k Views Asked by At

I need to create a custom textbox in the active slide with set text, font type, font size, font colour, and bold and italics feature in Powerpoint 2007 using a macro.

I am currently using this code:

Sub InsertTextBox()
Set myDocument = ActivePresentation.Slides(1)
Set newTextBox = myDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, _
    100, Top:=100, Width:=541.44, Height:=43.218)
    With newTextBox.TextFrame.TextRange
        .Text = "Slide Title"
        .Font.Size = 24
        .Font.Name = "Arial"
        .Font.Colour = RGB(107, 107, 107)  
End With
End Sub

Its throwing an exception in .Font.Colour saying that this property is not associated with the object. Also i need to incorporate a feature for bold and italics..Plz help me on this

2

There are 2 best solutions below

0
On

You can use Find on a range to locate a string within a textrange and return a new textrange consisting of just the found text:

With newTextBox.TextFrame.TextRange
    With .Find("Slide Title")
        .Font.Bold = True
    End With
End With

In practice, you'd want to use Instr to verify that the text you're looking for is indeed in the text box.

1
On

You want

.Font.Color.RGB = RGB(107, 107, 107)

And as Kazjaw points out, it's .Color rather than .Colour