Daniel Clímaco
Daniel Clímaco

Reputation: 85

Change Textbox written, properties (PowerPoint VBA)

I tryed the following code, to change the size of the font of the TextBox that is written the name in the TextBox 'txtboxselection'. For example if the text of the TextBox 'txtboxselection' is 'TextBox1' then it should change the font size of the TextBox1.

Private Sub TextBox2_Change()
Dim e_sel As TextBox
Set e_sel = txtboxselection.Text
e_sel.Font.Size = 11
End Sub

But, unfortunately it doesn't work ('Compile Error: Type mismatch'). So is there any way to tell the program that I want to change the font size of the TextBox written in the "txtboxselection' TextBox, because mine didn't work.

Upvotes: 1

Views: 1582

Answers (1)

Mathieu Guindon
Mathieu Guindon

Reputation: 71247

Assuming your textbox is an ActiveX control on a PowerPoint slide, you need to query the Shapes collection to get to the control, and retrieve its OLEFormat.Object to get a TextBox object:

Private Sub TextBox1_Change()
Dim box1 As TextBox
Set box1 = Me.Shapes("TextBox1").OLEFormat.Object
MsgBox box1.Font.Size
End Sub

Once you have your TextBox object reference, you can do anything you want with it. So in your case:

Private Sub TextBox2_Change()
Dim e_sel As TextBox
Set e_sel = Me.Shapes(txtboxselection.Text).OLEFormat.Object
e_sel.Font.Size = 11
End Sub

Upvotes: 1

Related Questions