user1025536
user1025536

Reputation: 11

Change the font of part of the text in a textbox in VBA

Ok, this hasn't been asked yet.

So, I recently started exploring VBA in PowerPoint. I started to make something that look like a text editor in a slideshow. But, the problem is that the buttons that I made that supposed to make the selected text become bold, italic or underline, changes the whole text inside the textbox into bold, italic or underlined texts.

The current method that I used to change the text font is this:

Private Sub CommandButton1_Click()
    If TextBox1.Text.Font.Bold = False Then
        TextBox1.Text.Font.Bold = True
    Else
        TextBox1.Text.Font.Bold = False
    End If
End Sub

Obviously, this code will make all the text in TextBox1 change into bold text when CommandButton1 is clicked. But, what should I do if I want only part of the text change into bold text (that is, the selected text)?

Upvotes: 1

Views: 9385

Answers (2)

Luke
Luke

Reputation: 1

I know that this works with dealing with VBA and powerpoint objects:

...Shape.TextFrame.TextRange.Characters(10, 15).Font.Color.RGB = RGB(, , )

...Shape.TextFrame.TextRange.Characters(10, 15).Font.Italic = msoTrue

I haven't tried in with excel text boxes.

Upvotes: 0

Steve Rindsberg
Steve Rindsberg

Reputation: 3528

As far as I know, you can't control the formatting of a text box's text, other than as a whole.

In VB, I think you could use a Rich Text Box control to do the job, but PPT/VBA doesn't supply one.

Upvotes: 1

Related Questions