VBA for Excel 2007 tutorial-VBA code to set text of controls


VBA code to set text of controls

In this example, you will learn VBA code to set text on controls on the form. To set the text on a control, you can use the Caption property of the control

To run this example VBA code, you will need a Form and some controls that support Caption property like Button.

VBA for Excel: VBA code example of using VBA code to set text displayed on controls.
VBA code to set background color of controls:

  Private Sub UserForm_Initialize()
    Dim i As Integer
    Dim obj As Object 'object variable
    For i = 0 To Me.Controls.Count - 1
      Set obj = Me.Controls(i) 'refer to each control
      obj.Caption = "Button" & i 'set its caption
    Next
End Sub



Comments





This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.