1 CS 106 Computing Fundamentals II Chapter 29 “Creating A User Form” Herbert G. Mayer, PSU CS Status 7/4/2013 Initial content copied verbatim from CS 106.

Slides:



Advertisements
Similar presentations
Using VB with MS Applications R. Juhl, Delta College.
Advertisements

Creating a User Form. A Better Interface Our programs can use input boxes for input and write on the spreadsheet page for output This works ok but is.
FrontPage Express By John G. Summerville Ph.D.©, RN.
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
Microsoft Office 2007 Excel Chapter 7 Using Macros and Visual Basic for Applications (VBA) with Excel.
Corporate Property Automated Information System (CPAIS) Macro Walkthrough Guide for Excel Version 2003.
How to get started with Excel VBA. We need to enable programming in Excel  the “Developer menu”
Adobe Photoshop CS Design Professional ADOBE PHOTOSHOP CS GETTING STARTED WITH.
Using the Visual Basic Editor Visual Basic for Applications 1.
Chapter 31 Visual Basic Controls A Form is a windows-style screen displayed by Visual Basic programs. In a form, a programmer can create objects in a form.
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Introduction to Visual Basic Chulantha Kulasekere.
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)
 Experiment with the Design features to get the look you want for your presentation.  Most design templates will keep the design the same on all your.
Adding Controls to User Forms. Adding Controls A user form isn’t much use without some controls We’re going to add controls and write code for them Note.
Introduction to VBA. This is not Introduction to Excel We’re going to assume you have a basic level of familiarity with Excel If you don’t, or you need.
Mastering Your Word Processing Skills
1 CS 106 Computing Fundamentals II Chapter 16 “Naming In Excel” Herbert G. Mayer, PSU CS Status 7/6/2013 Initial content copied verbatim from CS 106 material.
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.
1 CS 106 Computing Fundamentals II Chapter 17 “Introduction To VBA” Herbert G. Mayer, PSU CS status 6/30/2013 Initial content copied verbatim from CS 106.
VBA for Excel. What is a spreadsheet? u An Excel spreadsheet is a set of worksheets  Each worksheets is made up of rows and columns of cells  Rows are.
Ch 11: Userforms CP212 Winter Topics Designing User Forms o Controls Setting Properties o Tab Order o Testing Writing Event Handlers o Userform_Initialize.
Introduction to VBA MGMI Aug What is VBA? VBA = Visual Basic for Application Excel’s powerful built-in programming language An event-driven.
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.
1 CS 106 Computing Fundamentals II Chapter 25 “Variables, Assignment Statement” Herbert G. Mayer, PSU CS Status 7/4/2013 Initial content copied verbatim.
1 CS 106 Computing Fundamentals II Chapter 7 “Showing Developer Tab” Herbert G. Mayer, PSU CS status 6/17/2013 Initial content copied verbatim from CS.
INSERT BOOK COVER 1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Excel 2010 by Robert Grauer, Keith.
1 CS 106 Computing Fundamentals II Chapter 4 “Excel Basics for Mac” Herbert G. Mayer, PSU CS status 6/27/2013 Initial content copied verbatim from CS 106.
Chapter 12: Recording Macros Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
OCC Network Drives  H:\  P:\ 
A guide to creating a power point display Essentials Ctl M =New Slide: a new slide can be inserted. It is placed after the slide that you are viewing.
HTML Comprehensive Concepts and Techniques Second Edition.
How to get started with Excel VBA. We need to enable programming in Excel  the “Developer menu”
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
Chapter 2 – Introduction to the Visual Studio .NET IDE
1 CS 106 Computing Fundamentals II Chapter 84 “Array Formulae” Herbert G. Mayer, PSU CS status 6/14/2013 Initial content copied verbatim from CS 106 material.
1 CS 106 Computing Fundamentals II Chapter 67 “Working With Files” Herbert G. Mayer, PSU CS status 6/24/2013 Initial content copied verbatim from CS 106.
The Object Model. You can think of the contents of an Excel application as a hierarchy of collections of objects, manipulated by code Each object can.
1 CS 106 Computing Fundamentals II Chapter 23 “Controls And Events” Herbert G. Mayer, PSU CS Status 7/5/2013 Initial content copied verbatim from CS 106.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Showing the Developer Tab. Windows vs Mac This is one of the places where the Mac and Windows procedures are different. We’ll look at the Windows method.
1 CS 106 Computing Fundamentals II Chapter 211 “Coding And Debugging” Herbert G. Mayer, PSU CS status 6/29/2013 Initial content copied verbatim from CS.
1 CS 106 Computing Fundamentals II Chapter 210 “Adding Controls to User Forms” Herbert G. Mayer, PSU CS Status 7/4/2013 Initial content copied verbatim.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 3 Building an Application in the Visual Basic.NET Environment.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Visual Basic A Quick Tutorial VB Review for ACS 367.
1 CS 106 Computing Fundamentals II Chapter 28 “Scope” Herbert G. Mayer, PSU CS Status 7/14/2013 Initial content copied verbatim from CS 106 material developed.
1 CA202 Spreadsheet Application Automating Repetitive Tasks with Macros Lecture # 12 Dammam Community College.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Using Macros Lesson.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
The Advantage Series ©2005 The McGraw-Hill Companies, Inc. All rights reserved Chapter 12 Introducing Visual Basic for Applications Microsoft Office Excel.
1 CS 106 Computing Fundamentals II Chapter 85 “Excel Tables” Herbert G. Mayer, PSU CS status 6/14/2013 Initial content copied verbatim from CS 106 material.
CS 106 Computing Fundamentals II Chapter 5 “Excel Basics for Windows”
Chapter 2 – Introduction to the Visual Studio .NET IDE
Chapter Lessons Start Adobe Photoshop CS
3.01 Apply Controls Associated With Visual Studio Form
CS 106 Computing Fundamentals II Chapter 35 “Controls For Choices”
3.01 Apply Controls Associated With Visual Studio Form
Chapter 7 Advanced Form Techniques
CS 106 Computing Fundamentals II Chapter 66 “Working With Strings”
A few tricks to take you beyond the basics of Microsoft Office 2007
A few tricks to take you beyond the basics of Microsoft Office
I dragged over the label tool (A icon) and put it on the form.
CS 106 Computing Fundamentals II Chapter 69 “Event Loop”
Introduction to Visual Basic 2010
Presentation transcript:

1 CS 106 Computing Fundamentals II Chapter 29 “Creating A User Form” Herbert G. Mayer, PSU CS Status 7/4/2013 Initial content copied verbatim from CS 106 material developed by CS professors: Cynthia Brown & Robert Martin

2 Syllabus A Better Interface A Better Interface Goal Goal Windows Version... detailed Windows Version... detailed Change Name Change Name Properties Properties Mac Version... Abbreviated, but see video Mac Version... Abbreviated, but see video Showing Form Showing Form Viewing Code Viewing Code

3 A Better Interface Our programs can use input boxes for input and write on the spreadsheet page for outputOur programs can use input boxes for input and write on the spreadsheet page for output This works ok but is not very elegant or flexibleThis works ok but is not very elegant or flexible VBA gives us a way to create a custom form, known as the User Form, to use as an interface for your programVBA gives us a way to create a custom form, known as the User Form, to use as an interface for your program We’ll skim the Windows version, then look in detail at the Mac versionWe’ll skim the Windows version, then look in detail at the Mac version

4 Goal Presentation “Create_User_Form” is paired with “Add_Control_2_User_Form”Presentation “Create_User_Form” is paired with “Add_Control_2_User_Form” Overall goal is to show how to enter a string and then display the concatenated string in these steps:Overall goal is to show how to enter a string and then display the concatenated string in these steps: 1 A label prompts user to enter a string1 A label prompts user to enter a string 2 A text box reads this string input, e.g. “Cindy”2 A text box reads this string input, e.g. “Cindy” 3 A button, when subsequently pushed, causes the string concatenation and display event3 A button, when subsequently pushed, causes the string concatenation and display event 4 A second text box displays “This is: Cindy!”4 A second text box displays “This is: Cindy!”

5 WINDOWS VERSION

6 To Get Started… Open a new workbook, go to the Developer tab, and click Visual Basic. In VBA, double click ThisWorkBook in the project window to show the code sheet, and type OptionExplicit. Then click the Insert UserForm icon, and choose UserForm

7 Things to Notice Your new user form. Grab the bottom corner and drag to make it bigger. The toolbox has items you can put on the user form. If you don’t see it, click the toolbox icon (highlight ed above) Properties of the selected form or tool

8 Change the Name of the Form Name is the first property In the list. We will refer to the form by its name in our program.

9 Change the Caption Captio n propert y Here’s the caption. The user will see it when using the form. The user will not see the name.

10 Other Properties There are plenty of other properties to play with. You can try them out.There are plenty of other properties to play with. You can try them out. One fun one is the background color. Let’s set it to something other than white…One fun one is the background color. Let’s set it to something other than white…

11 User Form Made Yellow The BackC olor propert y The colors are reached through the little down arrow at the right of the property line. System colors are the ones Windows is using for your system. The Palette gives you some other options.

12 Showing the Form Unless you make it happen, the form won’t show up in your spreadsheet programUnless you make it happen, the form won’t show up in your spreadsheet program The line of code that makes the form show up isThe line of code that makes the form show up is formName.ShowformName.Show Let’s make it show up when you open the workbook, using the Workbook_Open() event procedure.Let’s make it show up when you open the workbook, using the Workbook_Open() event procedure. Double click in the project window to get back to the ThisWorkbook project, and type the code. Then close the workbook and reopen itDouble click in the project window to get back to the ThisWorkbook project, and type the code. Then close the workbook and reopen it

13 Here is the code…

14 Screen, after Opening Workbook

15 MAC VERSION

16 To Get Started Go to the Developer tab and then to the VBA editor. Under the InsertMenu, click Userform.

17 The new userfor m Controls you can add to the userform Properties window showing Userform properties Showing it In the project

18 Changing the Properties Use the properties window to change the propertiesUse the properties window to change the properties For each item, a separate properties window opens, but only after being clicked = selected!For each item, a separate properties window opens, but only after being clicked = selected! We’ll change the name to frmExampleWe’ll change the name to frmExample And we’ll make it bigger by changing the height to 450 and width to 600And we’ll make it bigger by changing the height to 450 and width to 600 We’ll also change the caption to “Welcome”We’ll also change the caption to “Welcome” And the backcolor to yellowAnd the backcolor to yellow

19 I couldn’t find a yellow I liked on the color wheel, so I used the “crayons” to select one

20 Here is the yellow form after I clicked OK.

21 Showing Form Right now there is nothing that makes the form show up when you are in the workbook.Right now there is nothing that makes the form show up when you are in the workbook. The command frmExample.Show makes it visibleThe command frmExample.Show makes it visible We could put this in a macro that is activated by clicking a button, but let’s put it in the special Workbook_Open() macro that makes it show up automatically, as a side-effect of the opening event, when you open the workbook.We could put this in a macro that is activated by clicking a button, but let’s put it in the special Workbook_Open() macro that makes it show up automatically, as a side-effect of the opening event, when you open the workbook.

22 I double clicked here to get the code window for this workbook I typed my code here

23 Viewing Code Option Explicit '***************************************** ' Show form frmExample when the workbook opens '***************************************** Sub Workbook_Open() frmExample.Show frmExample.Show End Sub

24 Save and quit… Save the workbook as a Macro-enabled (.xlsm) workbook and then quit ExcelSave the workbook as a Macro-enabled (.xlsm) workbook and then quit Excel The next slide shows the re-opened workbook with enabled macrosThe next slide shows the re-opened workbook with enabled macros

25 The user form caption