VBA PROGRAMMING FOR EXCEL FREDRIC B. GLUCK 608-698-6304

Similar documents
Excel macros made easy

Working with Macros and VBA in Excel 2007

Macros in Word & Excel

Automate tasks with Visual Basic macros

Microsoft Excel 2013: Macro to apply Custom Margins, Titles, Gridlines, Autofit Width & Add Macro to Quick Access Toolbar & How to Delete a Macro.

Excel basics. Before you begin. What you'll learn. Requirements. Estimated time to complete:

DATA 301 Introduction to Data Analytics Microsoft Excel VBA. Dr. Ramon Lawrence University of British Columbia Okanagan

Migrating to Excel 2010 from Excel Excel - Microsoft Office 1 of 1

MS WORD 2007 (PC) Macros and Track Changes Please note the latest Macintosh version of MS Word does not have Macros.

Basic Microsoft Excel 2007

Advanced Excel Charts : Tables : Pivots : Macros

Skill Set 4. Macros. By the end of this Skill Set you should be able to: Record a Macro Run a Macro Assign a Macro Create a Multiple Action Macro

Excel 2007 Introduction to Macros

WHAT S NEW IN MS EXCEL 2013

Introduction to Microsoft Excel 2010

To launch the Microsoft Excel program, locate the Microsoft Excel icon, and double click.

Excel 2007 Basic knowledge

Word basics. Before you begin. What you'll learn. Requirements. Estimated time to complete:

Microsoft Excel 2007 Level 2

In This Issue: Excel Sorting with Text and Numbers

NAVIGATION TIPS. Special Tabs

Excel 2007: Basics Learning Guide

Introduction to Microsoft Access 2003

Microsoft Access 2010 handout

Microsoft Excel Understanding the Basics

Microsoft Excel Introduction to Microsoft Excel 2007

Lab 11: Budgeting with Excel

SECTION 5: Finalizing Your Workbook

Microsoft Access 2010 Part 1: Introduction to Access

Working together with Word, Excel and PowerPoint 2013

ECDL. European Computer Driving Licence. Spreadsheet Software BCS ITQ Level 2. Syllabus Version 5.0

Excel & Visual Basic for Applications (VBA)

EXAMPLE WITH NO NAME EXAMPLE WITH A NAME

Excel Spreadsheets: Getting Started

Microsoft PowerPoint 2010

Microsoft Office. Mail Merge in Microsoft Word

Using the Advanced Tier Data Collection Tool. A Troubleshooting Guide

Google Apps for Sharing Folders and Collecting Assignments

Programming in Access VBA

Section 1: Ribbon Customization

Microsoft Migrating to Word 2010 from Word 2003

Microsoft Excel 2013 Tutorial

Lab 2: MS ACCESS Tables

MS Access Lab 2. Topic: Tables

Highline Excel 2016 Class 26: Macro Recorder

Word 2010: Mail Merge to with Attachments

Note: Only series and vector/matrix/scalar/string objects can be retrieved using this Add In.

Financial Data Access with SQL, Excel & VBA

State of Michigan Data Exchange Gateway. Web-Interface Users Guide

Instructions to operating forms created in MSWord and Excel

Microsoft Office Excel 2007 Key Features. Office of Enterprise Development and Support Applications Support Group

Task Force on Technology / EXCEL

Microsoft Excel Basics

Microsoft Excel 2010 Linking Worksheets and Workbooks

Mail Merge Creating Mailing Labels 3/23/2011

Computer Training Centre University College Cork. Excel 2013 Level 1

BulkSMS Text Messenger Product Manual

SPV Reporting Tool VBA Code User Guide. Last Updated: December, 2009

Microsoft Migrating to PowerPoint 2010 from PowerPoint 2003

Writing Macros in Microsoft Excel 2003

WHAT S NEW IN WORD 2010 & HOW TO CUSTOMIZE IT

Styles, Tables of Contents, and Tables of Authorities in Microsoft Word 2010

RIT Installation Instructions

EXCEL FINANCIAL USES

Skills Funding Agency

Sample- for evaluation purposes only! Advanced Excel. TeachUcomp, Inc. A Presentation of TeachUcomp Incorporated. Copyright TeachUcomp, Inc.

Microsoft Excel Training - Course Topic Selections

Advanced Presentation Features and Animation

New Features in Microsoft Office 2007

Access Using Access

USC Marshall School of Business Marshall Information Services

Microsoft Excel 2013: Headers and Footers

MS Excel. Handout: Level 2. elearning Department. Copyright 2016 CMS e-learning Department. All Rights Reserved. Page 1 of 11

warpct.com Working with MS Excel 2003 Workbook courseware by WARP! Computer Training

Excel 2013 What s New. Introduction. Modified Backstage View. Viewing the Backstage. Process Summary Introduction. Modified Backstage View

AARP Tax-Aide Helpful Hints for Using the Volunteer Excel Expense Form and Other Excel Documents

How To Understand The Basic Concepts Of A Database And Data Science

Tommy B. Harrington 104 Azalea Drive Greenville, NC

TurboNest. What s New. Version Released April Copyright 2014 Hypertherm, Inc. All rights reserved.

Creating trouble-free numbering in Microsoft Word

Adding Comments in Microsoft Excel 2003

Using Excel for Business Analysis: A Guide to Financial Modelling Fundamentals

Microsoft PowerPoint 2011

Microsoft Word Level 3

Microsoft Office Access 2007 which I refer to as Access throughout this book

Microsoft Office Access 2007 Basics

FRONTPAGE FORMS

Introduction to Microsoft Access 2013

In this example, Mrs. Smith is looking to create graphs that represent the ethnic diversity of the 24 students in her 4 th grade class.

Scientific Graphing in Excel 2010

EXCEL Using Excel for Data Query & Management. Information Technology. MS Office Excel 2007 Users Guide. IT Training & Development

SAP BusinessObjects Financial Consolidation Web User Guide

Quick Start Guide. Highly customizable automated trading Automate your trades according to rules and models you create.

Company Setup 401k Tab

Excel 2003 Tutorial I

Search help. More on Office.com: images templates. Here are some basic tasks that you can do in Microsoft Excel 2010.

Click on various options: Publications by Wizard Publications by Design Blank Publication

Explore commands on the ribbon Each ribbon tab has groups, and each group has a set of related commands.

CJA 20. Automated Billing Program Attorney Training Guide EXCEL BILLING FOR CJA CASES. Page 1

3 What s New in Excel 2007

Transcription:

VBA PROGRAMMING FOR EXCEL FREDRIC B. GLUCK FGLUCK@MADISONCOLLEGE.EDU FBGLUCK@GMAIL.COM 608-698-6304

Text VBA and Macros: Microsoft Excel 2010 Bill Jelen / Tracy Syrstad ISBN 978-07897-4314-5 Class Website for Excel Resources and downloadable files is at: learn.fbgluck.com

Syllabus-lite Very quick review and check in of your experience with Excel (low, medium, high) and with programming in other languages Guidelines of the class Expectations Attendance at all classes Cell phones Homework / Labs / Exams / Projects

About You Your Excel experience Have you ever done any programming (in any computer language?) How do you use Excel today? How would you like to be able to use Excel after completing this class?

What We Will Learn This is a class that will teach you computer programming as it applies to the Microsoft Excel environment We start with simple examples and work up to writing complete Visual Basic programs using control structures to accomplish programming tasks.

The Excel Programming Environment Excel VBA Module Excel VBA Module Programs Excel Functions Excel Macros Excel VBA Object MS Excel Operating System (MS Windows) Hardware Excel VBA Object Excel VBA Projects Excel Visual Basic for Applications (VBA) Programs

VBA (Visual Basic for Applications) Excel macros, functions and programs are written in the VBA programming language VBA can be used for ALL Microsoft Office applications Some of what we learn here (Excel) can be used in other office apps VBA lineage is from BASIC added MS office specific functions added object-oriented programming

Getting Things Automated in Excel VBA programs Level of automation Add: additional statements and multiple functions Excel Custom Functions (extend commands and can be used in Macros) Add: program flow control (logic) Recorded commands (MACROS) User entered keyboard commands Level of complexity

Enabling Macros and VBA Developer options are hidden from the everyday user FILE > OPTIONS > CUSTOMIZE RIBBON Check DEVELOPER BOX to turn on Developers Tab

Relative vs Absolute Referencing (Recording) Absolute Referencing: Excel records the absolute value of the cells. Example: Excel records you selected Cell E4 Relative Referencing: Excel records you moved down three cells from the current cell Question: Which should you use?

Macro Security Macros can carry malicious code The default security settings are do not run macros Protection Schemes... Create Trusted Locations (folders) to store workbooks: DEVELOPER > MACRO SECURITY Adjust Global Security Settings for Macros: DEVELOPER > MACRO SECURITY > MACRO SETTINGS Macro Enabled Workbooks - SAVE AS...

Excel File Types.xlsx: An Excel file in XML form. Cannot store Macros.xlsm: An Excel file that can store macros.xlsb: An Excel file in binary format. Designed for very large spreadsheets (1.1 million rows).xls: An Excel file that can be read by versions prior to 2010. Can contain macros You can customize Excel to always produce xlsm files. FILE > EXCEL OPTIONS > SAVE > SAVE FILES IN THIS FORMAT

Macro Security Workbooks in trusted areas can always run macros regardless of other settings Macro settings control macro access for workbooks outside of trusted locations The Enable All Macros is not recommended Disable All Macros With Notification is recommended

Terminology Macro Visual Basic Module Macro and VBA Programming Environment Excel Workbook

What is a Macro Recorded keystrokes that can be played back to automate (repeat) a task. Macros have no flow control. Keystrokes are always played in the same order Examples where Macros are useful: Reformatting data by removing spaces or replacing a string of characters. To repeat find and replace commands To run document setup actions (e.g. insert a header, footer or other document id information) Macro Code is "written" by recording keystrokes

Modules A container for storing code (Macros) Attached to (part of) an Excel Workbook Macro Macro Macro Macro Macro Macro Module Module Module Module

The Macro Recorder

How to Create A Macro (VBA SubRoutine) Macros are written by recording the series of keystrokes that are used to accomplish a task. Example: Turn on Macro Recorder Step 1 Step 2 Sub (macro_name) End Sub Step n Turn off Macro Recorder

Create Macros with the Macro Recorder The Macro Recorder is available only in MS Word and MS Excel From the DEVELOPER TAB, choose RECORD MACRO Specify the properties of the Macro: The name of the macro (No spaces. Begins with letter or underscore. Must be unique to the workbook) A shortcut key assigned to the macro Where to store the macro A description of the macro

Recording Macros After the dialog box, recording begins EVERYTHING is recorded (keyboard, menu selections) Mouse actions are recorded in EXCEL, not in WORD Icon at bottom indicates Recording is on To stop recording: VIEW > MACROS > STOP RECORDING Click on the MACRO icon

Quick Ways to Run Macros Short keys are case sensitive Ctl+e is not the same as Ctl+E If you use E, you need to type CTL+Shift+E Open (non-assigned) lower case keys are e,j,m and q Assigned (Upper case) keys are: A, F, O and P

Quick Ways to Run Macros Macros can be assigned to the Quick Access Toolbar Choose the customize Quick Access Toolbar command (Dropdown from the quick access toolbar) > MORE COMMANDS > From the CHOOSE COMMANDS FROM LIST choose MACROS Choose the symbol and complete the display name

Quick Ways to Run Macros You can also assign a Macro to a Form Control, Text Box or Shape DEVELOPER > INSERT >Form Control Button Click the top left location of the button Assign the macro Modify the button (text, size etc.)

Where Do I Store Macros? Two Options: (specified when you define a macro) In your current workbook Travels with the workbook Only available when the workbook is open In the Personal Macro Workbook When you record a Macro -- Store Macro In: Personal Macro Workbook Creates a hidden workbook on your machine called PERSONAL.XLSB. This workbook is stored in: C: \Users\<username>\AppData\Roaming\Microsoft\Excel\XL START Does not exist until you save a macro into this workbook Can be unhidden: VIEW > UNHIDE > PERSONAL

Changing Macro Properties Macro Properties Macro Name Shortcut Key Description Change these properties by: VIEW > MACROS > (select macro) WARNING: Avoid assigning shortcut key that is used by Excel (e.g. ctl+b, ctl+c etc.) Excel will override it s internal command and run your macro in case of a conflict (see pg 11 in the book for additional information)

Exercises

Exercise #1 Create a Macro that fills in cells A2 to A11 with the values 1 through 10. Store this Macro in the spreadsheet you are working on Assign a shortcut key and an icon on the Quick Access Toolbar to this macro. Assign a button on the worksheet called "Count 1 to 10" to this macro. Save the worksheet and re-open it. Make sure the macro runs correctly

Exercise #2 Create a macro that clears the contents of the workbook moves the cursor to cell A1 fills the cells from A1 to A7 with the days of the week Fills the cells from B1 to B7 with the day numbers (assume that Monday is day #1) Save the macro to your Personal Macro Workbook Make sure to unhide this spreadsheet Assign a shortcut key and Quick Access Icon to this macro Save and close the worksheet Open a new worksheet and run the macro you just defined

Exercise #3 Create a setup macro that you run immediately after you open a new spreadsheet Adds your company name to the workbook header Adds a worksheet Renames the worksheets to North East West and South Adds a page # of # pages and file name and prepared by your name to each section of the footer. Save the macro (think of where you should save it) Close the spreadsheet Open a new spreadsheet, run your setup macro and run the macro you defined in Exercise #2

Exercise #4 Data Reformat Once a week, you get a report of delinquent accounts from the accounting legacy system. You want to use the data to send letters via MS WORD. Open the csv file accounting_data.csv from the MATC "cloud" i:\fb_gluck\accounting.csv Create a macro that reformats the names, address1 and address2 so that each of the elements is in one column. Hint: running the macro once will take one "set" of data and reformat it. You will have to run the macro once for each individual set of data. If you want, try to modify the macro so that you can run it once and reformat the entire sheet.