Visual Basic for Applications (VBA) An object-oriented programming language –Instructions for the manipulation of objects –A structured way to provide.

Slides:



Advertisements
Similar presentations
Sep-05 Slide:1 VBA in Excel Walter Milner. Sep-05 Slide:2 VBA in Excel Introduction VBA = Visual Basic for Applications Enables end-user programming In.
Advertisements

Visual Basic for Applications (VBA) An object-oriented programming language –Instructions for the manipulation of objects –A structured way to provide.
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.
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 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.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
With Microsoft Excel 2010 © 2011 Pearson Education, Inc. Publishing as Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Excel 2010.
Advanced Microsoft Word Hosted by Jared Hoffman Topics Keyboard Shortcuts Customizing Toolbars and Menus Auto Format & Auto Correct Tabs Inserting Pictures.
Using the Visual Basic Editor Visual Basic for Applications 1.
Customizing Menus and Toolbars. Manipulating Command Bars Customize: –Right-click any place on a command bar and cick Customize … Customize window: –Toolbars,
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)
Excel VBA and Macros Excel uses a language to implement all of the functional capability of the application. VBA (Visual Basic for Applications) is that.
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Macros and VBA A macro is a set of instructions that tells Excel which commands to execute.
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
Lab 8 Solver In VBA ► Review – Solver Add-in In Excel ► Solver Add-in In VBA.
With Microsoft Excel 2007 Comprehensive 1e© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Excel 2007 Comprehensive.
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.
Microsoft Excel 2007 © Wiley Publishing All Rights Reserved. The L Line The Express Line to Learning L Line.
Copyright 2007, Paradigm Publishing Inc. EXCEL 2007 Chapter 7 BACKNEXTEND 7-1 LINKS TO OBJECTIVES Record & run a macro Record & run a macro Save as a macro-
Creating Macros Using VBA. Assigning a Macro to a Button Display the Forms toolbar. Click the Button icon. Click and drag the mouse pointer to specify.
Microsoft Office 2007 FastFacts May 6, Topics The Microsoft Office Button The Quick Access Toolbar The Ribbon The Mini Toolbar.
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.
OV Copyright © 2011 Element K Content LLC. All rights reserved.  Create a Macro with the Macro Recorder  Edit a Macro  Debug a Macro  Customize.
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.
 An object-oriented programming language ◦ Instructions for the manipulation of objects ◦ A structured way to provide instructions to Excel  Excel has.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
Chapter 12: Recording Macros Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Visual Basic for Applications Macro Programming For Microsoft Office.
Visual Basic for Applications (VBA) An object-oriented programming language –Instructions for the manipulation of objects –A structured way to provide.
Intro to Excel - Session 7.31 Tutorial 7 - Session 7.3 Developing an Excel Application.
VBA Lab 2 I ns.Samia Al-blwi. Visual Basic Grammar Object: Visual Basic is an object-oriented language. This means that all the items in Excel are thought.
OCC Network Drives  H:\  P:\ 
Chapter 9 Macros And Visual Basic For Applications.
Visual Basic  Is the language for programming in Word, Access,& Excel  Is the “Environment” in which the programming is done (called the Integrated Development.
Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Running Solver through a Macro Solver dialog box must have been opened at least once in current Excel session (i.e. Solver must be currently activated.
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft® Excel 2013.
Introduction to Microsoft Excel Macros COE 201- Computer Proficiency.
BBT 10 Visual Basic 03 Enrichment. Tip Before creating any files for your project, first create a new folder Save all of your files in the folder Pieces.
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft® Excel 2013.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
1 CA202 Spreadsheet Application Automating Repetitive Tasks with Macros Lecture # 12 Dammam Community College.
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.
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.
Exploring Excel Chapter 7 Automating Repetitive Tasks: Macros and
Outline In this module, the following topics will be covered:
Microsoft Office Illustrated
Microsoft Excel 2003 Illustrated Complete
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 تقن , المعمل الخامس
Macro.
Lesson 1 - Automating Tasks
Microsoft Office Excel 2003
Tutorial 11 Using and Writing Visual Basic for Applications Code
Microsoft Excel 2007 – Level 2
Presentation transcript:

Visual Basic for Applications (VBA) An object-oriented programming language –Instructions for the manipulation of objects –A structured way to provide instructions to Excel Excel has an Object Library that defines its set of objects (e.g. workbooks, charts, ranges of cells)

Logic of Language First part of a command identifies the object Second part of command: –Sets a property of the object (e.g. color or font) –Takes an action on the object (e.g.copy or move) –Sets an attribute to the object (e.g. assigns a value to it using := )

Example of an Instruction Application.Workbooks(“Book1.xls”).Work sheets(“Sheet1”).Range(“A1”).Font.Name= “Arial” Application.Workbooks(“Book1.xls”).Work sheets(“Sheet1”).Range(“A1”) is the object Font.Name=“Arial” is the property being set

Control of VBA A Procedure is a set of instructions that operate on a set of objects A Function is a procedure that returns a value as a result A Subroutine is a procedure that can be run or used by another macro

VBA Toolbar (Excel 2003)

Developer Tab (Excel 2007)

BlueCell Macro Sub bluecell() ' ' bluecell Macro ' With Selection.Interior.Pattern = xlSolid.PatternColorIndex = xlAutomatic.Color = TintAndShade = 0.PatternTintAndShade = 0 End With End Sub

Running Macros Run Macro option Shortcut Keys: [Ctrl][Shift] letter Command Buttons Custom Toolbar

Running Solver through a Macro Solver dialog box must have been opened at least once in current Excel session (i.e. Solver must be currently activated in Excel) SolverSolve UserFinish:=True Tools Reference option in VBA must have Solver selected Other VBA commands for controlling Solver in class handout

Debugging VBA Code When VBA encounters a problem, it will highlight line in yellow. Use [f8] key to step through code Use the Reset icon button (square) at top of VBA to exit step-through mode and trouble- shoot code or Excel/VBA settings. Cannot retry macro until yellow highlight is gone.

Plotting the Efficient Frontier – Version 1A Command Button Private Sub EfficientFrontier_Click() Range("C53") = Range("B59") SolverSolve UserFinish:=True Range("D59") = Range("C51") End Sub

Plotting the Efficient Frontier – Version 1B Command Button Private Sub EfficientFrontier_Click() For unit = 1 To 11 Range("C53") = Range("B" & 58 + unit) SolverSolve UserFinish:=True Range("D" & 58 + unit) = Range("C51") Next unit End Sub