How to Access VBA Variable Font Size
- 1). Click your application's "Developer" tab, and then click the "Visual Basic" button to enter the VBA programming environment. Click the "Insert" menu, and then click the "Userform" item to insert a new form. This form can hold controls whose font properties you can change with VBA statements.
- 2). Click the "View" menu, and then click the "Toolbox" item to display a palette of controls. Click the tool palette icon shaped like the two characters "Ab" to load the Text box control, and then drag on the Userform to create a text box.
- 3). Click the tool palette icon shaped like a button to enter button-drawing mode, and then drag on the canvas below the text box you placed to create a button for the form.
- 4). Double-click the button to display the event function for the Click event. This function executes when your program's user presses the button you placed on the form. Type the following statements in the coding window. These statements read from and write to the "Size" property of the text box. Writing to this property allows you to change the font size of any text typed into the text box.
Private Sub CommandButton1_Click()
If TextBox1.Font.Size > 5 Then
TextBox1.Font.Size = 2
TextBox1.Font.Size = 20
- 5). Press "F5" to run the program, and then type some text in the text box. Click the button several times, noticing the size of the text in the text box, which changes increases or decreases with each mouse click.