Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.

Slides:



Advertisements
Similar presentations
Introduction to Macro Introduction to Visual Basic for Application Recording a Macro Looking at the code of Recorded Macro.
Advertisements

© Paradigm Publishing, Inc Excel 2013 Level 2 Unit 2Managing and Integrating Data and the Excel Environment Chapter 7Automating Repetitive Tasks.
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.
Copyright 2007, Paradigm Publishing Inc. EXCEL 2007 Chapter 6 BACKNEXTEND 6-1 LINKS TO OBJECTIVES Workbook properties Workbook properties Workbook Sharing.
1 CA202 Spreadsheet Application Collaborating with Colleagues Lecture # 16 Dammam Community College.
1 Linking & Consolidating Worksheets Applications of Spreadsheets.
Using Macros and Visual Basic for Applications (VBA) with Excel
Tutorial 7: Developing an Excel Application
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.
Copyright © 2008 Pearson Prentice Hall. All rights reserved Copyright © 2008 Prentice-Hall. All rights reserved. Committed to Shaping the Next.
Microsoft Office Excel 2013 Core Microsoft Office Excel 2013 Core Courseware # 3253 Lesson 8: Macros, Importing and Exporting Data.
MACROS CS1100 Computer Science and its Applications CS11001.
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.
Customizing Word Microsoft Office Word 2007 Illustrated Complete.
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.
Using the Visual Basic Editor Visual Basic for Applications 1.
Microsoft Excel 2003 Illustrated Complete Excel and Advanced Worksheet Management Customizing.
1 Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. by Mary Anne Poatsy, Keith Mulbery, Eric Cameron, Jason Davidson, Rebecca Lawson,
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)
Macros in Excel Intro to lab 1. Macroinstructions Macro is recorded in VBA module sequence of Excel operations Macros can automate tasks in Excel Macro.
Excel Lesson 14 Creating and Using Macros Microsoft Office 2010 Advanced Cable / Morrison 1.
Microsoft Office Word 2013 Expert Microsoft Office Word 2013 Expert Courseware # 3251 Lesson 4: Working with Forms.
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.
Word Lesson 16 Working with Macros Microsoft Office 2010 Advanced Cable / Morrison 1.
Microsoft Office Word 2013 Core Microsoft Office Word 2013 Core Courseware # 3250 Lesson 8: Using Productivity Tools.
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.
Microsoft ® Office 2007 Training Security II: Turn off the Message Bar and run code safely John Deere presents:
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 © 2008 Pearson Prentice Hall. All rights reserved. 1 Exploring Microsoft Office Word 2007 Chapter 7 The Advanced User Robert Grauer, Keith Mulbery,
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 22 Macros.
1 CA201 Word Application Increasing Efficiency Week # 13 By Tariq Ibn Aziz Dammam Community college.
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-
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.
INSERT BOOK COVER 1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Excel 2010 by Robert Grauer, Keith.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. a lesson approach Microsoft® Excel 2010 © 2011 The McGraw-Hill Companies,
1. Chapter 25 Protecting and Preparing Documents.
Intro to Excel - Session 7.31 Tutorial 7 - Session 7.3 Developing an Excel Application.
OCC Network Drives  H:\  P:\ 
Microsoft Access 2010 Chapter 10 Administering a Database System.
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft® Excel 2013.
Securing and Sharing Workbooks Lesson 11. The Review Tab Microsoft Excel provides several layers of security and protection that enable you to control.
Introduction to Microsoft Excel Macros COE 201- Computer Proficiency.
Chapter 11 Enhancing an Online Form and Using Macros Microsoft Word 2013.
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft® Excel 2013.
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.
Microsoft Excel Illustrated Introductory Workbooks and Preparing them for the Web Managing.
Chapter 11 Enhancing an Online Form and Using Macros Microsoft Word 2013.
Excel Tutorial 8 Developing an Excel Application
Data Validation and Protecting Workbook
Developing an Excel Application
Microsoft Excel 2003 Illustrated Complete
Microsoft Word 2003 Illustrated Complete
Introducing VBA Macros
Exploring Microsoft® Word® 2016 Series Editor Mary Anne Poatsy
Exploring Microsoft Excel
Lesson 1 - Automating Tasks
Microsoft Office Excel 2003
Microsoft Excel 2007 – Level 2
Presentation transcript:

Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013

Use passwords to assign protected and unprotected status to a worksheet Use the macro recorder to create a macro Execute a macro and view and print code for a macro Customize the Quick Access Toolbar by adding a button Use a Data Form to add data to a Worksheet Objectives Using Macros, Controls and Visual Basic for Applications (VBA) with Excel2

Understand Visual Basic for Applications (VBA) code and explain event-driven programs Add controls such as command buttons, option buttons, and check boxes to a worksheet Assign properties to controls Review a digital signature on a workbook Using Macros, Controls and Visual Basic for Applications (VBA) with Excel3 Objectives

Using Macros, Controls and Visual Basic for Applications (VBA) with Excel4 Project – Waterfront Studios

Before a computer can take an action and produce a desired result, it must have a step-by- step description of the task to be accomplished The step-by-step description is a series of precise instructions called a procedure Program and code are other names for a procedure The process of writing a procedure is called computer programming Using Macros, Controls and Visual Basic for Applications (VBA) with Excel5 Writing a Procedure

Because Excel does not have a command or button for every possible worksheet task, Microsoft has included a powerful programming language called Visual Basic for Applications Visual Basic for Applications (VBA) is a programming language that allows you to customize and extend the capabilities of Excel Using Macros, Controls and Visual Basic for Applications (VBA) with Excel6 Visual Basic for Applications (VBA)

A macro is a procedure composed of VBA code It is called a macro rather than a procedure because it is created using the macro recorder You can create a macro to group together commonly used combinations of tasks, which then can be reused later Use macros to ensure consistency in calculations, formatting, and manipulation of nonnumeric data Macros save time and automate repetitive tasks Using Macros, Controls and Visual Basic for Applications (VBA) with Excel7 Macros

Excel includes a macro recorder that can record a series of actions and save them as a macro The macro recorder can be turned on, during which time it records your activities, and then turned off to stop the recording After recording a macro, you can play it back, or execute it, as often as you want to repeat the steps you recorded with the macro recorder Using Macros, Controls and Visual Basic for Applications (VBA) with Excel8 Recording a Macro

Three steps must be taken in preparation for working with macros in Excel – The DEVELOPER tab, which be default does not appear on the ribbon, must be made available by changing an Excel option – Second, a security setting in Excel must be modified to enable macros whenever you use Excel – Finally, Excel requires a workbook that includes macros to be saved as an Excel Macro-Enabled Workbook file type Using Macros, Controls and Visual Basic for Applications (VBA) with Excel9 Working with Macros

Using Macros, Controls and Visual Basic for Applications (VBA) with Excel10 Displaying the DEVELOPER Tab

A macro is created by performing a set of steps and recording the steps as they are performed The steps and their order should be determined and rehearsed before creating the macro When you create a macro, you assign a name to it A macro name can be up to 255 characters long; it can contain numbers, letters, and underscores, but it cannot contain spaces or other punctuation The name is used later to identify the macro when you want to execute it Executing a macro causes Excel to step through all of the recorded steps just as they were recorded Using Macros, Controls and Visual Basic for Applications (VBA) with Excel11 Naming and Executing a Macro

Once you start recording a macro, any task you perform in Excel will be part of the macro If you make a mistake while recording a macro, delete the macro and record it again Using Macros, Controls and Visual Basic for Applications (VBA) with Excel12 Recording a Macro

You can set a keyboard shortcut key combination for executing a macro with an option in the Record Macro dialog box Using Macros, Controls and Visual Basic for Applications (VBA) with Excel13 Setting a Keyboard Shortcut in a Macro

Using Macros, Controls and Visual Basic for Applications (VBA) with Excel14 Recording a Macro to Reformat the Artist Data Where First Name Appears First

Macros provide you with an opportunity to make certain tasks much more efficient and accurate However, macros introduce an element of risk to your work in the form of computer viruses Macros are known carriers of viruses because of the ease with which a person can add programming code to macros Using Macros, Controls and Visual Basic for Applications (VBA) with Excel15 Macros and Viruses

Excel provides four levels of protection from macro viruses: Disable all macros without notification, Disable all macros with notification, Disable all macros except digitally signed macros, and Enable all macros By default, the macro security level is set to Disable all macros with notification, meaning that only macros from trusted sources can be used Using Macros, Controls and Visual Basic for Applications (VBA) with Excel16 Setting the Macro Security Level

Using Macros, Controls and Visual Basic for Applications (VBA) with Excel17 Setting the Macro Security Level

Excel remembers your decision about enabling macros If you have enabled macros in a worksheet, Excel will not ask you about enabling them the next time you open the worksheet, but will open the worksheet with macros enabled If you are uncertain about the reliability of the source of a workbook and its macros, you can work with the macros disabled, which means that the code is not executable If you are confident of the source of a workbook and its macros, click the Enable Content button on the SECURITY WARNING bar Using Macros, Controls and Visual Basic for Applications (VBA) with Excel18 Enabling/Disabling Macros

When you work with a workbook created by someone else, you should review the content and structure of the workbook before you make changes to it You can learn more about a workbook by doing as much of the following as possible to the worksheet: – Display any formulas to gain an understanding of what formulas and functions are used in the worksheet and which cells are referenced by the formulas and functions – Use Range Finder or the auditing commands to show which cells are referenced in formulas and functions – Check which cells are locked and which cells are unlocked – Enter sample data and verify the results Using Macros, Controls and Visual Basic for Applications (VBA) with Excel19 Working with a Workbook Created by Someone Else

A password ensures that users cannot unprotect a worksheet simply by clicking the Unprotect button Passwords in Excel can contain, in any combination, letters, numbers, spaces, and symbols and can be up to 15 characters long Passwords are case sensitive If you decide to password-protect a worksheet, make sure you write down the password and keep it in a secure place If you lose the password, you cannot open or gain access to the password-protected worksheet Using Macros, Controls and Visual Basic for Applications (VBA) with Excel20 Creating a Password

Using Macros, Controls and Visual Basic for Applications (VBA) with Excel21 Unprotecting a Password-Protected Worksheet

With the worksheet unprotected, you can modify the contents of the cells Cells must both be locked and the worksheet protected to restrict what users can do to cell contents Using Macros, Controls and Visual Basic for Applications (VBA) with Excel22 Restricting Users

Use the PROPER function to convert names entered in all uppercase to mixed case Using Macros, Controls and Visual Basic for Applications (VBA) with Excel23 Converting Names to Proper Case

Use the Paste Values command when you want to replace a formula with a text value Using Macros, Controls and Visual Basic for Applications (VBA) with Excel24 Pasting Values

Use the LEN function to determine the total number of characters in a name Using Macros, Controls and Visual Basic for Applications (VBA) with Excel25 Using the LEN Function

A macro is composed of VBA code, which is created automatically by the macro recorder The Visual Basic Editor is used by all Office applications to enter, modify, and view Visual Basic for Application code Using Macros, Controls and Visual Basic for Applications (VBA) with Excel26 Viewing a Macro’s VBA Code

Excel provides a feature for entering data when the content is straightforward text or numbers A data form is created from a range of cells, and uses the column headings from that range to create the fields on the form Data forms are particularly helpful when working with a series of columns that would otherwise require you to scroll horizontally, or when entering a large number of entries into a worksheet Using Macros, Controls and Visual Basic for Applications (VBA) with Excel27 Using a Data Form to Enter Additional Records

Using Macros, Controls and Visual Basic for Applications (VBA) with Excel28 Using a Data Form to Enter Additional Records

Two types of controls are used to create the user interface: form controls and ActiveX controls Form controls and ActiveX controls look identical in the gallery They do have function differences, however, that can help determine which one is the best choice for an object Form controls require no knowledge of VBA to use Using Macros, Controls and Visual Basic for Applications (VBA) with Excel29 Form Controls and ActiveX Controls

You can assign an Excel macro directly to a form control, allowing the macro to be run with a simple click Form controls also allow you to reference cells easily and use Excel functions and expressions to manipulate data Using Macros, Controls and Visual Basic for Applications (VBA) with Excel30 Adding Form Controls to a Worksheet

Using Macros, Controls and Visual Basic for Applications (VBA) with Excel31 Adding Form Controls to a Worksheet

ActiveX controls provide great flexibility in terms of their design They have extensive properties that can be used to customize their appearance Using Macros, Controls and Visual Basic for Applications (VBA) with Excel32 ActiveX Controls

Using Macros, Controls and Visual Basic for Applications (VBA) with Excel33 Grouping Option Buttons in a User Interface With form controls, only one of the option buttons on the form can be selected unless the option buttons are grouped Use the group box form control to group one set of the option buttons together

Using Macros, Controls and Visual Basic for Applications (VBA) with Excel34 Grouping Option Buttons in a User Interface

Using Macros, Controls and Visual Basic for Applications (VBA) with Excel35 Adding a Command Button Control to the Worksheet A command button control can have Visual Basic code associated with it that accomplishes more complex actions than a macro or a form button can accommodate

Each form control and ActiveX control available in the Controls gallery has many properties, or characteristics, that can be set to determine the control’s appearance and behavior Using Macros, Controls and Visual Basic for Applications (VBA) with Excel36 Formatting the Controls

Using Macros, Controls and Visual Basic for Applications (VBA) with Excel37 Formatting the Controls

Using the Controls gallery to insert a command button control into a worksheet inserts an object only To have the button take action when a user clicks it, you must write VBA code that directs the events in the worksheet after the command button is clicked The next step is to write and enter the procedure that will execute when the user clicks the button Using Macros, Controls and Visual Basic for Applications (VBA) with Excel38 Writing VBA Code

Using Macros, Controls and Visual Basic for Applications (VBA) with Excel39 Using the Visual Basic Editor

After you determine what you want the procedure to do, write the VBA code on paper Test the code before you enter it in the Visual Basic Editor, by stepping through the instructions one at a time yourself As you do so, think about how the procedure affects the worksheet This process is called desk checking, and it is an important part of the development process Using Macros, Controls and Visual Basic for Applications (VBA) with Excel40 Desk Checking

Comments are used to document each procedure This will help you remember its purpose at a later date or help somebody else understand its purpose Comments begin with the word Rem (short for Remark) or an apostrophe Comments have no effect on the execution of a procedure; they simply provide information about the procedure, such as name, creation date, and function Using Macros, Controls and Visual Basic for Applications (VBA) with Excel41 Using Comments to Document a Procedure

Using Macros, Controls and Visual Basic for Applications (VBA) with Excel42 Using Comments to Document a Procedure

Some users prefer to attach a digital signature to verify the authenticity of a document A digital signature is an electronic, encrypted, and secure stamp of authentication on a document This signature confirms that the file originated from the signer and that it has not been altered Using Macros, Controls and Visual Basic for Applications (VBA) with Excel43 Attaching a Digital Signature

The digital signature references a digital certificate A digital certificate is an attachment to a file or message that vouches for its authenticity, provides secure encryption, or supplies a verifiable signature Many users who receive files enable the macros based on whether they are digitally signed by a developer on the user’s list of trusted sources Using Macros, Controls and Visual Basic for Applications (VBA) with Excel44 Digital Certificates