UserForm.

Slides:



Advertisements
Similar presentations
Microsoft Expression Web-Illustrated Unit J: Creating Forms.
Advertisements

An Introduction to Visual Basic Terms & Concepts.
Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Excel Project 7 Using Macros and Visual Basic for Applications (VBA) with Excel.
Using Macros and Visual Basic for Applications (VBA) with Excel
Tutorial 12: Enhancing Excel with Visual Basic for Applications
Excel and VBA Creating an Excel Application
Automating Tasks With Macros
Visual Basic Project Files:.VBP file: Project File: a small text file that contains the names of other files in the project, as well as some information.
Automating Tasks With Macros. 2 Design a switchboard and dialog box for a graphical user interface Database developers interact directly with Access.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
Slide 1 Chapter 2 Visual Basic Interface. Slide 2 Chapter 2 Windows GUI  A GUI is a graphical user interface.  The interface is what appears on the.
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Lab 9 – User Forms Design. User Forms What are user forms? –Known as dialog boxes –Major ways for getting user input An example of using user forms: Monthly.
IN THE NAME OF ALLAH UserForms on VBA Lab 06 Tahani Al_dweesh.
Automating Tasks with Visual Basic. Introduction  When can’t find a readymade macro action that does the job you want, you can use Visual Basic code.
Ch 11: Userforms CP212 Winter Topics Designing User Forms o Controls Setting Properties o Tab Order o Testing Writing Event Handlers o Userform_Initialize.
Chapter 11: Introduction to the Visual Basic Environment Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University.
Week 8.  Recap  User Forms  Input Validation Message Boxes Input Boxes  Conversion Functions.
An Introduction to Visual Basic
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
Creating your own form from scratch.. To create a custom form, you can modify an existing form or design and create a form from scratch. In either case,
Lab 01 Forms in excel Tahani ALdweesh Insert form into your project. 2. Change form’s properties. 3. Put controls on the form. 4. Change controls’
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
Copyright © 2001 by Wiley. All rights reserved. Chapter 2: Using Visual Basic to Create a First Project Getting Started with VB Development Environment.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
ME 142 Engineering Computation I Custom Dialog Boxes.
Chapter Two Creating a First Project in Visual Basic.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Lab 10. User Forms Design – Code Part ► Lab 9 Review ► Continue ‘Student Record’ Example ► A Car Loan Application.
Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.
How to: Simple User Interface WMCUG 13 th Jan 2010 Gord Vander Vliet Enterprise Tool & Die, LLC Jeff Roark Johnson Controls.
Introducing UserForms Joanna Wyrobek 1. Ms Excel UserForms A UserForm object is a window or dialog box that makes up part of an application's user interface.
Working with UserForms Dr Joanna Wyrobek 1. Displaying a modeless UserForm By default, UserForms are displayed modally. This means that the UserForm must.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
Chapter 8 Multiple Forms, Modules, and Menus. Introduction This chapter demonstrates how to: – Add multiple forms to a project – Create a module to hold.
Visual Basic.NET Windows Programming
Working in the Forms Developer Environment
Chapter 1: An Introduction to Visual Basic 2015
Chapter Topics 15.1 Graphical User Interfaces
Chapter 2 – Introduction to the Visual Studio .NET IDE
GO! with Microsoft Access 2016
1. Introduction to Visual Basic
Even More VBA IE 469 Spring 2017.
Using Procedures and Exception Handling
Excel VBA Day 3 of 3 Tom Vorves.
An Introduction to Visual Basic
User Forms.
Microsoft Excel 2003 Illustrated Complete
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Chapter 2 Visual Basic Interface
Custom dialog boxes Unit objectives
Exploring Microsoft Excel
CIS16 Application Development Programming with Visual Basic
Chapter 15: GUI Applications & Event-Driven Programming
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Custom Forms with VBA in Excel In-Class Exercise #11
Microsoft Excel 2007 – Level 2
Presentation transcript:

UserForm

USERFROM BASICS UserForm is useful if you need to get some information from users A dialog box can be created to handle such situation from the users This dialog box is created on a userform in the VBE and it is displayed by using a VBA macro The official name for a dialog box in VBA is a userform But userform is really an object that contains what is commonly known as dialog box When designing a userform, yu are creating what developers call the Graphical User Interface (GUI)

USERFROM BASICS Designing a useform can also be referred to as an object oriented interface The main key to creating a userform is to take some time to think or research about how the form should look like and how you want the users to interact with the elements on the form What is essential is to understand how you will guide your users through the steps they need to take on the form by carefully considering the arrangements and wordings of the controls Remember, like most things, the more you practise it, the easier it gets

CREATING USERFORMS Determine how the dialog box will be used and at what point it will be displayed in your VBA macro Activate the VBE and insert a new userform objet Add controls to the iuserform Use the properties window to modify the properties for the controls or for the userform itself Write event-handler procedures for the controls( macro codes that executes when the user clicks a button in the dialog box). This code is stored in the userform window Write a procedure that will display the dialog box to the user. This code is stored in the VBA module

To create this Userform, execute the following steps. Open the Developer-Visual Basic-Insert-UserForm 2. Your screen should be set up as below.

Userform with Multiple Pages we will look at how to create a Userform that contains multiple pages. The Multipage Control contains two pages. At page 1, the user can fill in his/her personal information. At page 2, the user can indicate which programme he/she want to register for and the session he/she wish to commence the programme This will require the following controls Multipage control, labels, text boxes (first at the top, the second below the first), frame, option buttons (first at the left, the second at the right), list box, Image control and command button. Each of this control can be created: Multipage control by clicking on Multipage from the Toolbox. When you arrive at the Gender frame, remember to draw this frame first before you place the two option buttons in it.

Remember to take note of the name tag and the caption you assign to each of the control. These tags are needed in the Excel VBA code. Captions are those that appear on your screen. It is good practice to change the names of the controls, but it is not necessary here because we only have a few controls in this example. To change the caption of the Userform, Multipage tabs, labels, frame, option buttons and command button, click View, Properties Window and click on each control.

Create the second Userform1 Again take note of the names and caption tags The UserForm is to serve as the Student Registration Portal to contain two pages namely: Personal Information and Programme Registered Personal Information should consist of Name Age Gender- Male or Female Programme Registered should consist of Programme Enrolled Programme Session Now create an Excel as shown below

To Command button1, write the following codes to Register Me We can now write Excel macro code to allocate our entry into the Excel file This will be written for Command button1 so that when it is clicked, after filling the required pages, the data will be transferred into the Excel file. To Command button1, write the following codes to Register Me Private Sub CommandButton1_Click() Dim emptyRow As Long   Sheet1.Activate emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1 Cells(emptyRow, 1).Value = TextBox1.Value Cells(emptyRow, 1).Columns.AutoFit Cells(emptyRow, 2).Value = TextBox2.Value  If OptionButton1.Value = True Then Cells(emptyRow, 3).Value = "Male" Else Cells(emptyRow, 3).Value = "Female" End If  Cells(emptyRow, 4).Value = ListBox1.Value  End Sub

The next thing now is to assign the list for the Listbox1, combobox1, we can also preset the invoice and shipped to the actual date that the entries are made, and we can set the first items to be filled first. To this end, we have to initialize the UserForm to be able to perform this by writing the following codes Private Sub UserForm_Initialize()   With ListBox1 .AddItem "Fall Semester" .AddItem "Spring Semester" .AddItem "Summer School" .AddItem "Orientation" End With ComboBox1.List = Array("Industrial Engineering", "Economics", "Computer Engineering", "Mechanical Engineering", "Civil Engineering", "Mathematics") End Sub To Exit from the records, we shall have to write macro code for the Commanbutton2: Close Registration Private Sub CommandButton2_Click() Unload Me

Create the second Userform2 Again take note of the names and caption tags The UserForm is to take invoice particulars to contain three pages namely: Customers details, Product details and shipment details. Customer Details should consist of Invoice No Invoice Date Customer Name Customer Address Mobile Product Details should consist of Product Description Quantity Ordered Unit Price Total Amount

Shipment Details should consist of Invoice No Invoice Date Transportation Mode (Air, Land, Rail, Road) Date Shipped Destination Command button 1: Lodge Customer Order Records Command button2: Exit Records Your Userform2 with Caption: INVOICE PARTICULARS should look like this

To Command button1, write the following codes to customer details We can now write Excel macro code to allocate our entry into the Excel file This will be written for Command button1 so that when it is clicked, after filling the required pages, the data will be transferred into the Excel file. To Command button1, write the following codes to customer details Private Sub CommandButton1_Click() Dim LastRowCustomerDetails As Long, LastRowProductDetails As Long, LastRowShipmentDetails As Long LastRowCustomerDetails = Sheets("CustomerDetails").Range("A" & Rows.Count).End(xlUp).Row Sheets("CustomerDetails").Cells(LastRowCustomerDetails + 1, "A").Value = TextBox1.Text Sheets("CustomerDetails").Cells(LastRowCustomerDetails + 1, "B").Value = TextBox2.Text Sheets("CustomerDetails").Cells(LastRowCustomerDetails + 1, "C").Value = TextBox3.Text Sheets("CustomerDetails").Cells(LastRowCustomerDetails + 1, "D").Value = TextBox4.Text Sheets("CustomerDetails").Cells(LastRowCustomerDetails + 1, "E").Value = TextBox5.Text End Sub

Product and Shipment details can be written is a similar form to transfer the entries made on them to the Excel file as; LastRowProductDetails = Sheets("ProductDetails").Range("A" & Rows.Count).End(xlUp).Row Sheets("ProductDetails").Cells(LastRowProductDetails + 1, "A").Value = TextBox1.Text Sheets("ProductDetails").Cells(LastRowProductDetails + 1, "B").Value = TextBox2.Text Sheets("ProductDetails").Cells(LastRowProductDetails + 1, "C").Value = TextBox6.Text Sheets("ProductDetails").Cells(LastRowProductDetails + 1, "D").Value = TextBox7.Text Sheets("ProductDetails").Cells(LastRowProductDetails + 1, "E").Value = TextBox8.Text Sheets("ProductDetails").Cells(LastRowProductDetails + 1, "F").Value = TextBox9.Text Sheets("ProductDetails").Cells(LastRowProductDetails + 1, "F").Value = Val(TextBox7.Text) * Val(TextBox8.Text)   LastRowShipmentDetails = Sheets("ShipmentDetails").Range("A" &Rows.Count).End(xlUp).Row Sheets("ShipmentDetails").Cells(LastRowShipmentDetails + 1, "A").Value = TextBox1.Text Sheets("ShipmentDetails").Cells(LastRowShipmentDetails + 1, "B").Value = TextBox2.Text Sheets("ShipmentDetails").Cells(LastRowShipmentDetails + 1, "C").Value = ComboBox1.Text Sheets("ShipmentDetails").Cells(LastRowShipmentDetails + 1, "D").Value = TextBox11.Text Sheets("ShipmentDetails").Cells(LastRowShipmentDetails + 1, "E").Value = TextBox12.Text End Sub

The next thing now is to assign the list for the combobox, we can also preset the invoice and shipped to the actual date that the entries are made, and we can set the first items to be filled first. To this end, we have to initialize the UserForm to be able to perform this by writing the following codes Private Sub UserForm_Initialize() TextBox1.SetFocus TextBox2.Text = Date TextBox11.Text = Date ComboBox1.List = Array("By Land", "By Rail", "By Sea", "By Air") End Sub

The next thing now is to assign the list for the combobox, we can also preset the invoice and shipped datesTry to run Command button1 with these codes You should have all your entries in the Excel file created, inside their respective pages To Exit from the records, we shall have to write macro code for the Commanbutton2: Exit Records Private Sub CommandButton2_Click() Unload Me End Sub

We can just be switching between userforms within the same Excel file. Multiple UserForms can be created within the same Excel file to serve different purposes Instead of creating multiple Excel files, we can create multiple UserForms to take different Information from the users. We can just be switching between userforms within the same Excel file. For example we can create a switch macro codes for switching between our UserForm1 and Userform2 using the codes below; Private Sub CommandButton2_Click() Unload Me UserForm1.Hide UserForm2.Show End Sub Try and demonstrate this to see how it is possible to switch between UserForms in a single Excel file.

Thanks for listening remember , lab final is on the 25th of may there will not make-up lab exams