SlideServe
Menu
Préférences
© SlideServe · v2026

Mastering VBA in Excel: A Guide to User Forms and Programming Basics

idona-martinez avatar
21 diapositives · 350 Views · Oct 30, 2014

Dive into the essentials of Visual Basic for Applications (VBA) within Excel in this comprehensive guide. Learn to create and manipulate user forms, customize form properties, and use controls effectively. This tutorial walks you through inserting forms, changing properties, and writing code to enhance your Excel projects. Discover the Visual Basic Editor (VBE) environment and gain insights into variable declaration and assignment. With examples and detailed instructions, you will be equipped to elevate your Excel programming skills.

Mastering VBA in Excel: A Guide to User Forms and Programming Basics - slide 1
01 / 21Mastering VBA in Excel: A Guide to User Forms and Programming Basics
1 / 17

Télécharger la présentation

Mastering VBA in Excel: A Guide to User Forms and Programming Basics
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Lab 01 Forms in excel TahaniALdweesh In The Name Of Allah

  2. 1. Insert form into your project. 2. Change form’s properties. 3. Put controls on the form. 4. Change controls’ properties. 5. Write code. 6. Use Show method to display the form. Tahani ALdweesh objectives

  3. VBA : • Standard programming language for office programs . • Can be used in any office applications in same way . • As you do more work with VBA you will need to use VBE(Visual Basic Editor ), TahaniALdweesh VBA Visual Basic For Application

  4. :The Visual Basic Editor (VBE) is the environment in which you work with VBA programming code. TahaniALdweesh Visual Basic Editor

  5. TahaniALdweesh -Open Microsoft Excel - Tools > Macro > Visual Basic Editor (2003) ALT + F11 .user form < -insert

  6. TahaniALdweesh • The Visual Basic Editor windows Project window User Form Work Area properties window

  7. Project window: shows a hierarchical view of the contents of the current VBA project view  project explorer or Ctrl+R Properties window: shows the various properties available for whatever object that is highlighted view  Properties window or F4 User form window : the design area ,the toolbox will appear by default insert user form Code window: where the procedures take place view code or F7 Work area: the rest of the VBE TahaniALdweesh

  8. Properties are the physical descriptions of all Excel objects, and the description of the particular property is called the value of the property. Contains detailed information about any selected part of a project in .the Project Explorer TahaniALdweesh Properties Window

  9. TahaniALdweesh ToolBoxs ToolBox

  10. • Label: used to instruct the user • Textbox: enables the user to enter textual info. • List box: list of choices. • Checkbox: allow you to choose more than one option. • Combo box: is so named because it combines the function of textbox and a list box. • Option buttons: restricts the user to one choice. • Frame: used for: 1-groups option buttons 2-visually, arranging different portions of the form TahaniALdweesh

  11. In term of VB, variablesare areas allocated by the computer memory to hold data. Like the mail boxes, each variablemust be given a name.To name a variable in Visual Basic, you have to follow a set of rules. Tahani ALdweesh Vb code

  12. variablesThe following are the rules when naming the :in Visual Basic • It must be less than 255 characters. • Must start with a letter (a to z, A to Z). • It must not begin with a number. • No spacing is allowed . • Can contain any number of letters or digits (a digit is 0 to 9). • Can contain the underscore. TahaniALdweesh Variable Names

  13. TahaniALdweesh Examples of valid and invalid variablenames

  14. Declaring Variables In Visual Basic, one needs to declare the variables before using them by assigning names and data types. They are normally declared in the general section of the codes' windows using the Dim statement. The format is as follows: DimVariable Name As Data Type TahaniALdweesh Vb code

  15. Dim password As String Dim yourName As String Dim firstnum As Integer Dim secondnum As Integer Dim total As Integer Dim doDate As Date • You may also combine them in one line , separating each variable with a comma, as follows: Dim password As String , yourName As String, firstnum As Integer TahaniALdweesh Example

  16. Constants are different from variables in the sense that their values do not change during the running of the program. Declaring a Constant ConstConstant Name As Data Type = Value :• Example Const Pi As Single=3.142 Const Temp As Single=37 Const Score As Single=100 TahaniALdweesh Constraints

  17. After declaring various variables using the Dim statements, we can assign :values to those variables. The general format of an assignment is Variable=Expression • The variable can be a declared variable or a control property value. • The expression could be a mathematical expression, a number, a string, a Boolean value (true or false) and more. TahaniALdweesh Assigning Values to Variables

  18. firstNumber=100 secondNumber=firstNumber-99 userName="John Lyan" userpass.Text = password Label1.Visible = True Command1.Visible = false Label4.Caption = textbox1.Text ThirdNumber = Val(usernum1.Text) total = firstNumber+secondNumber+ThirdNumber TahaniALdweesh Examples:

  19. TahaniALdweesh Circle aRea Program :

  20. Private Sub CommandButton1_Click() Dim rad As Double rad = Val(TextBox1.Text) Dim area As Double area = 3.17 * rad * rad TextBox2.Text = area End Sub Private Sub CommandButton2_Click() UserForm1.Hide End Sub TahaniALdweesh The Code is :

  21. TahaniALdweesh Any Question