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.

Slides:



Advertisements
Similar presentations
1 VBA Introduction. Basic Components 2 VBA LANGUAGE OFFICE OBJECTS EXCEL OBJECTS ACCESS OBJECTS WORD OBJECTS OUTLOOK OBJECTS POWERPOINT OBJECTS.
Advertisements

Excel Object Model.
Introduction to Macro Introduction to Visual Basic for Application Recording a Macro Looking at the code of Recorded Macro.
Object Oriented Programming A programming concept which views programs as objects with properties and ways to manipulate the object and the properties.
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
Copyright © 2008 Pearson Prentice Hall. All rights reserved Copyright © 2008 Prentice-Hall. All rights reserved. Committed to Shaping the Next.
XP New Perspectives on Microsoft Excel 2003, Second Edition- Tutorial 8 1 Microsoft Office Excel 2003 Tutorial 8 – Developing an Excel Application.
How to get started with Excel VBA. We need to enable programming in Excel  the “Developer menu”
Writing VBA Macros Record a new Macro, recording only the name, shortcut and description Stop recording Open macro for editing and enter VB code Test.
Programming Excel Macros, Visual Basic, and Solving Your Problem.
Macros Excel built-in functions are great but limited Macros are a means for the user to define new functions A macro is a single command that automates.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
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.
Introduction to Class Modules Please use speaker notes for additional information!
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.
Microsoft Excel 2007 © Wiley Publishing All Rights Reserved. The L Line The Express Line to Learning L Line.
VBA (Visual Basic for Applications) What is Excel, just a spreadsheet? Time for Demos...
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.
Introduction to Engineering Computing GEEN 1300 Lecture 7 15 June 2010 Review for midterm.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Microsoft Excel Macros & Excel Solver (IENG490)
Introduction to VBA MGMI Aug What is VBA? VBA = Visual Basic for Application Excel’s powerful built-in programming language An event-driven.
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
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.
University of Toronto at Scarborough © Andria Hunter, Kersti Wain-Bantin CSCA01 VBA 1 Lecture Outline Record macro and examine VBA code VBA Editor (IDE)
® Microsoft Access 2010 Tutorial 11 Using and Writing Visual Basic for Applications Code.
Spreadsheets in Finance and Forecasting Presentation 9 Macros.
Visual Basic for Applications Macro Programming For Microsoft Office.
Intro to Excel - Session 7.31 Tutorial 7 - Session 7.3 Developing an Excel Application.
# 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.
Week 4.  Recap – Ranges  For Each Loops  Ranges Referencing Range Objects  Set (keyword)
1 MIS309 Database Systems Introduction to Microsoft Access.
P6 BTEC Level 3 Subsidiary Diploma in ICT. Automation The end user of a spreadsheet may be proficient in using the software, but the more that you automate.
ME 142 Engineering Computation I Using Subroutines Effectively.
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.
Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Excel Macros 1 Macros or, How to Automate Part of Your Spreadsheet or Worksheet.
© VBA JETPACK Introduction to VBA.
Variables and the Assignment Statement. Basics of Variables To represent any values that a process needs to remember, we use variables Recall that variables.
ME 142 Engineering Computation I Using Subroutines Effectively.
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.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Financial Information Management VB, VBA, VS, VSTO & VBE: Putting it all together Source: Excel VBA Programming by John Walkenbach.
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.
Scope. Scope of Names In a small program written by one person, it is easy to be sure that each variable has a unique name In a large program, or one.
Developing an Excel Applications
IE 8580 Module 4: DIY Monte Carlo Simulation

Microsoft Office Illustrated
Excel VBA Day 3 of 3 Tom Vorves.
Learning Excel Session 9 and 10 Dr. Chaitali Basu Mukherji.
Objectives Learn about Function procedures (functions), Sub procedures (subroutines), and modules Review and modify an existing subroutine in an event.
Exploring Microsoft Excel
أ.إسراء الطريقي أ. هاله الشملان , 102 تقن , المعمل الخامس
Microsoft Office Excel 2003
Custom Form with Spin Button Controls with VBA in Excel In-Class Exercise #12 Objective: Enhance a “standard” DSS interface with a custom “user form”
Tutorial 11 Using and Writing Visual Basic for Applications Code
Excel VBA Programming © Copyright 2011, TechMentors All rights reserved.
Presentation transcript:

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 to design to implementation and testing, on a very simple process Later we’ll gradually introduce VB features that let us implement more complex processes

But First… 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 problem

Relating VBA to Processes We 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 them The process events will be translated into control events for which we will write procedures

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

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

The Video You can watch the steps of writing the macro and adding the button on the video called Button Demo The workbook is available on the class site After 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 it

Events Clicking 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 spreadsheet Later we will also write macros that can be called by other macros

Referring to Objects and Properties Consider the expression ActiveCell.Interior.Color = vbRed ActiveCell 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 cell Color is a property of the Interior, and as such can be set to a value by an assignment statement

Properties vs Variables We’ll often be setting the 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 cell Besides properties of objects, we’ll also use more general variables for quantities we want our program to remember and work with