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.

Slides:



Advertisements
Similar presentations
Object Oriented Programming A programming concept which views programs as objects with properties and ways to manipulate the object and the properties.
Advertisements

Essence of programming  Branching  Repetitions.
Visual Basic for Applications. What it does Extends the features and built in functions of Excel – Create and run VB procedures – Some may be easy to.
Developing an Excel Application
Tutorial 8: Developing an Excel Application
XP New Perspectives on Microsoft Excel 2003, Second Edition- Tutorial 8 1 Microsoft Office Excel 2003 Tutorial 8 – Developing an Excel Application.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
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.
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
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.
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.
Macros n Macros are little programs that you can create to automate particular tasks that you may want to execute more easily than having to specify all.
Project 9 Using Visual Basic for Applications (VBA) to Customize and Automate Excel Jason C. H. Chen, Ph.D. Professor of Management Information Systems.
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.
EXCEL 2007 MACROS.  TOM FARRAR OF CNEXTWAVE INC.  GOAL : LEARNING ABOUT EXCEL MACROS.  PRESENTATION INCLUDES DISCUSSION AND DEMONSTRATION.  QUESTIONS.
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.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Microsoft Excel Macros & Excel Solver (IENG490)
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.
® Microsoft Access 2010 Tutorial 11 Using and Writing Visual Basic for Applications Code.
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 29 “Creating A User Form” Herbert G. Mayer, PSU CS Status 7/4/2013 Initial content copied verbatim from CS 106.
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.
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.
1 CS 106 Computing Fundamentals II Chapter 34 “Conditionals In Excel” Herbert G. Mayer, PSU CS Status 7/17/2013 Initial content copied verbatim from CS.
Visual Basic for Applications Macro Programming For Microsoft Office.
# 1# 1 CS 105 Spring 2010 Macros: Sub Procedures You Record What is a macro? What is With…End With? What is Sub…End Sub? Relative vs. Absolute.
1 CS 106 Computing Fundamentals II Chapter 61 “Loops” Herbert G. Mayer, PSU CS Status 7/29/2013 Initial content copied verbatim from CS 106 material developed.
1 CS 106 Computing Fundamentals II Chapter 32 “Boolean Expressions” Herbert G. Mayer, PSU CS Status 7/14/2013 Initial content copied verbatim from CS 106.
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 MIS309 Database Systems Introduction to Microsoft Access.
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.
1 CS 106 Computing Fundamentals II Chapter 75 “Arrays” Herbert G. Mayer, PSU CS Status 7/31/2013 Initial content copied verbatim from CS 106 material developed.
ME 142 Engineering Computation I Using Subroutines Effectively.
1 CS 106 Computing Fundamentals II Chapter 21 “Computer Organization” Herbert G. Mayer, PSU CS Status 7/9/2013 Initial content copied verbatim from CS.
Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Controls and Events. The Next Step In the first module, we discussed general problem solving In this module, we’ll apply what we learned, from specification.
Excel Macros 1 Macros or, How to Automate Part of Your Spreadsheet or Worksheet.
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.
Introduction to Microsoft Excel Macros COE 201- Computer Proficiency.
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.
1 CS 106 Computing Fundamentals II Chapter 6 “How To Zip & Unzip Files” Herbert G. Mayer, PSU CS status 6/17/2013 Initial content copied verbatim from.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
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.
Financial Information Management VB, VBA, VS, VSTO & VBE: Putting it all together Source: Excel VBA Programming by John Walkenbach.
1 CS 106 Computing Fundamentals II Chapter 42 “Sub Procedures And Functions” Herbert G. Mayer, PSU CS Status 8/5/2013 Initial content copied verbatim from.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
VBA Excel Macro 1.Create a Macro: To create a macro in Excel VBA, Create a Macro: To create a macro in Excel VBA,Create a Macro: To create a macro.
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.
Developing an Excel Applications
IE 8580 Module 4: DIY Monte Carlo Simulation
CS 106 Computing Fundamentals II Chapter 5 “Excel Basics for Windows”

CS 106 Computing Fundamentals II Chapter 35 “Controls For Choices”
CS 106 Computing Fundamentals II Chapter 77 “Algorithm”
CS 106 Computing Fundamentals II Chapter 33 “Conditional Statements”
Excel VBA Day 3 of 3 Tom Vorves.
Objectives Learn about Function procedures (functions), Sub procedures (subroutines), and modules Review and modify an existing subroutine in an event.
Exploring Microsoft Excel
CS 106 Computing Fundamentals II Chapter 71 “Indexing”
Foundations for Algebra
CS 106 Computing Fundamentals II Chapter 73 “Ranges”
CS 106 Computing Fundamentals II Chapter 66 “Working With Strings”
Herbert G. Mayer, PSU CS Status 8/2/2013
CS 106 Computing Fundamentals II Chapter 64 “For Loop Variations”
CS 106 Computing Fundamentals II Chapter 69 “Event Loop”
Excel VBA Programming © Copyright 2011, TechMentors All rights reserved.
Presentation transcript:

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 material developed by CS professors: Cynthia Brown & Robert Martin

2 Syllabus Next Step Next Step Relating to VBA Processes Relating to VBA Processes Macros Macros Code Code Events Events Referring to Objects, Properties Referring to Objects, Properties

3 Next Step Previously, we discussed general problem solvingPreviously, we discussed general problem solving In this module, we’ll apply what we learned, from specification to design to implementation and testing, to VBA on a very simple processIn this module, we’ll apply what we learned, from specification to design to implementation and testing, to VBA on a very simple process Later we’ll gradually introduce VB features that let us implement more complex processesLater we’ll gradually introduce VB features that let us implement more complex processes

4 But First… We have to learn enough about VBA and Excel to write an interesting program!We have to learn enough about VBA and Excel to write an interesting program! So our goal in this module is to learn those basics and apply them to a problemSo our goal in this module is to learn those basics and apply them to a problem

5 Relating VBA to Processes We will typically represent the objects in our process specification by Excel or VBA controls and other Excel and VBA objectsWe will typically represent the objects in our process specification by Excel or VBA controls and other Excel and VBA objects Objects and controls have events associated with themObjects and controls have events associated with them The process events will be translated into control events for which we will write proceduresThe process events will be translated into control events for which we will write procedures

6 Macros We’re going to start by writing (not recording) a small macro with a button to control itWe’re going to start by writing (not recording) a small macro with a button to control it This will introduce a number of basic conceptsThis will introduce a number of basic concepts

7 Code Option Explicit '***************************************** ' Turn the active cell red '***************************************** Sub RedCell() ActiveCell.Interior.Color = vbRed ActiveCell.Interior.Color = vbRed End Sub

8 The Video You can watch the steps of writing the macro and adding the button on the video called Button DemoYou can watch the steps of writing the macro and adding the button on the video called Button Demo The workbook is available on the Spring 2013 class siteThe workbook is available on the Spring 2013 class site After you watch, try writing your own macro, say GreenButton, in the same worksheetAfter you watch, try writing your own macro, say GreenButton, in the same worksheet Give it a button and/or a piece of clip art to activate itGive it a button and/or a piece of clip art to activate it

9 Events Clicking the button or the clip art is an event that triggers the execution of the macroClicking the button or the clip art is an event that triggers the execution of the macro This is a pattern we will continue to follow: our macros will be triggered by events that happen in the spreadsheetThis is a pattern we will continue to follow: our macros will be triggered by events that happen in the spreadsheet Later we will also write macros that can be called by other macrosLater we will also write macros that can be called by other macros

10 Referring to Objects, Properties Consider the expressionConsider the expression ActiveCell.Interior.Color = vbRed ActiveCell is an object recognized by Excel: the cell that has been selected in the active worksheetActiveCell is an object recognized by Excel: the cell that has been selected in the active worksheet Interior is a subobject of the ActiveCell: it’s just the interior of the cellInterior is a subobject of the ActiveCell: it’s just the interior of the cell Color is a property of the Interior, and as such can be set to a value by an assignment statementColor is a property of the Interior, and as such can be set to a value by an assignment statement

11 Properties vs. Variables We’ll often set values of properties of objectsWe’ll often set values of properties of objects Cells in particular have a property called the Value: ActiveCell.Value = 5 will make the number 5 show up in the cellCells in particular have a property called the Value: ActiveCell.Value = 5 will make the number 5 show up in the cell Besides properties of objects, we’ll also use more general variables for quantities we want our program to remember and work withBesides properties of objects, we’ll also use more general variables for quantities we want our program to remember and work with