Excel & Visual Basic for Applications (VBA)

Similar documents
P R E M I E R. Microsoft Excel 2007 VBA (Macros) Premier Training Limited 4 Ravey Street London EC2A 4QP Telephone +44 (0)

Introducing VBA Message Boxes

Excel & Visual Basic for Applications (VBA)

Creating Applications using Excel Macros/Visual Basic for Applications (VBA)

A Concise Guide for Beginners LIEW VOON KIONG

Word 2010: Mail Merge to with Attachments

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

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

To create a histogram, you must organize the data in two columns on the worksheet. These columns must contain the following data:

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

Programming in Access VBA

Fig. 1 The finished UserForm project.

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

WHAT S NEW IN MS EXCEL 2013

Instructions for Creating an Outlook Distribution List from an Excel File

1. a procedure that you perform frequently. 2. Create a command. 3. Create a new. 4. Create custom for Excel.

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

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

Macros in Word & Excel

Task Force on Technology / EXCEL

Using Excel As A Database

Part A: Introduction to Excel VBA

Excel 2003: Ringtones Task

Introduction to Microsoft Access 2003

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

Excel Reports and Macros

Creating a table of contents quickly in Word

Automate tasks with Visual Basic macros

Excel 2010: Create your first spreadsheet

Excel Pivot Tables. Blue Pecan Computer Training Ltd - Onsite Training Provider :: :: info@bluepecan.co.

Tommy B. Harrington 104 Azalea Drive Greenville, NC

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

RIT Installation Instructions

EXCEL VBA ( MACRO PROGRAMMING ) LEVEL SEPTEMBER AM-5.00PM MENARA PJ@AMCORP PETALING JAYA

Financial Data Access with SQL, Excel & VBA

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

Scientific Graphing in Excel 2010

Working with Macros and VBA in Excel 2007

EXCEL Tutorial: How to use EXCEL for Graphs and Calculations.

Creating tables of contents and figures in Word 2013

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

How To Use Excel With A Calculator

Training Needs Analysis

Excel macros made easy

Advanced Excel 10/20/2011 1

Basic Pivot Tables. To begin your pivot table, choose Data, Pivot Table and Pivot Chart Report. 1 of 18

Word 2007: Basics Learning Guide

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

Chapter 4 Displaying and Describing Categorical Data

Microsoft Excel Introduction to Microsoft Excel 2007

Pivot Tables & Pivot Charts

Microsoft Access 2010 Overview of Basics

Excel Companion. (Profit Embedded PHD) User's Guide

Customization Manager in Microsoft Dynamics SL 7.0

To Begin Customize Office

LabVIEW Report Generation Toolkit for Microsoft Office User Guide

Excel Database Management Microsoft Excel 2003

Microsoft Excel 2007 Level 2

Microsoft Word 2011: Create a Table of Contents

3 What s New in Excel 2007

Construction Administrators Work Smart with Excel Programming and Functions. OTEC 2014 Session 78 Robert Henry

Spreadsheet - Introduction

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

Using SPSS, Chapter 2: Descriptive Statistics

Microsoft Excel 2013 Tutorial

2Creating Reports: Basic Techniques. Chapter

Getting Started with Excel Table of Contents

Smart Connection 9 Element Labels

What is Microsoft Excel?

Chapter 9 Creating Reports in Excel

Microsoft Access Basics

Microsoft PowerPoint 2010

Excel 2007: Basics Learning Guide

Using Microsoft Word to Create Your Theses or Dissertation

Excel Reporting with 1010data

Produced by Flinders University Centre for Educational ICT. PivotTables Excel 2010

To export data formatted for Avery labels -

ESSENTIAL TOOL FOR ACCOUNTANTS MICROSOFT EXCEL TM JEFFERSON HASKINS CPA

Microsoft PowerPoint 2008

Hands-on Exercise 1: VBA Coding Basics

Data Analysis with Microsoft Excel 2003

BID2WIN Workshop. Advanced Report Writing

Introduction to Microsoft Excel 2010

Using the Advanced Tier Data Collection Tool. A Troubleshooting Guide

Microsoft Migrating to PowerPoint 2010 from PowerPoint 2003

USC Marshall School of Business Marshall Information Services

Advanced Presentation Features and Animation

Create a PivotTable or PivotChart report

SAP BUSINESS OBJECT ANALYSIS FOR EXCEL DEVELOPER GUIDE

Intro to Excel spreadsheets

Macros allow you to integrate existing Excel reports with a new information system

Computer Training Centre University College Cork. Excel 2013 Pivot Tables

To add a data form to excel - you need to have the insert form table active - to make it active and add it to excel do the following:

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

Sage Intelligence Report Designer Add-In

New Features in Microsoft Office 2007

Transcription:

Excel & Visual Basic for Applications (VBA) user interfaces o on-sheet buttons o toolbar buttons and custom toolbars o custom menus o InputBox and MsgBox functions o userforms 1 On-Sheet Buttons 1) use the Forms toolbar to place a button on the worksheet 2) assign a macro to the button 3) format the button as desired activate the Forms toolbar from the View menu 2 1

On-Sheet Buttons draw button on worksheet assign button to macro [ Note: assignment asked for automatically in Excel 2002] 3 On-Sheet Buttons change button text change font style 4 2

On-Sheet Buttons click button to run macro use on-sheet buttons for macros dedicated to the workbook and worksheet, often to launch userforms 5 Toolbar Buttons use toolbar buttons for tasks common to many workbooks, like editing tasks, e.g., center and wrap a title in the cell Tools Customize Commands tab Macros 6 3

Toolbar Buttons click on "happy face" button change button image drag and place on formatting toolbar in a convenient location pick from collection of standard buttons, or... 7 Toolbar Buttons Button Editor select Edit Button Image... erase the happy face (yea!) create new design 8 4

Toolbar Buttons select Assign Macro... macro typically from Personal.xls, in order to be general to all open workbooks it is possible to add toolbar buttons when a certain workbook opens and remove them when the workbook closes, but this takes some extra work and is unusual 9 Toolbar Buttons change button name to indicate function close Customize window test button and macro select headings & click CW button result widen column manually 10 5

Toolbar Buttons toolbar buttons are mainly of use on your own computer system, not one of the lab systems they are best used for special formatting macros that you want to apply to a variety of worksheets in different workbooks toolbar buttons are sometimes used to run macros that are part of an Add-In these are usually put on their own custom toolbar which is installed and "docked" with the other toolbars when the Add-In is activated 11 Custom Toolbars Tools Customize Toolbars tab click New... button type in toolbar name: new, empty toolbar created and docked at the top 12 6

Custom Toolbars drag CW button to new toolbar more buttons could be added a single toolbar is used to organize buttons that have a common theme, e.g., special formatting buttons or a dedicated engineering Add-In like calculations for flow in pipelines once again, it is possible to display an entire toolbar only when a given workbook is opened and have it removed when the workbook is closed 13 Custom Menus Tools Customize Commands tab New Menu category click on New Menu and drag to menu bar 14 7

Custom Menus change menu name drag commands to menu, both custom & built-in begin a menu group drag to menu completed menu Modify Selection 15 InputBox Function simplified version InputBox( prompt, title, default value ) optional typical use Xin = InputBox( Enter value for x: ) [ assign result of InputBox to variable for later use ] complete version InputBox( prompt, title,default,xpos,ypos,helpfile,context) optional 16 8

InputBox Method (alternative to InputBox Function) object.inputbox( prompt, title, default, xpos, ypos, helpfile, context, type) type codes 0 formula 1 number 2 string 4 logical 8 cell reference 16 error value, e.g., #N/A 64 array of values optional codes can be combined to allow for inputs of multiple types, e.g., 3 for number or string 17 InputBox Method (alternative to InputBox Function) 18 9

MsgBox Function MsgBox( prompt,buttons, title,helpfile,context) optional text displayed in the message box prompt items must be combined with & MsgBox The answer is & Xval & tons button codes vbokonly 0 vbexclamation 48 vbokcancel 1 vbinformation 64 vbabortretryignore 2 vbdefaultbutton1 0 vbyesnocancel 3 vbdefaultbutton2 256 vbyesno 4 vbdefaultbutton3 512 vbretrycancel 5 vbdefaultbutton4 768 vbcritical 16 vbsystemmodal 4096 vbquestion 32 MsgBox result is button clicked by user 19 MsgBox Function MsgBox Return Value vbok 1 vbcancel 2 vbabort 3 vbretry 4 vbignore 5 vbyes 6 vbno 7 Putting line breaks into the message displayed 20 10

UserForms (custom dialog boxes) the most flexible (and complicated) user interface feature Illustrate by example: a typical engineering formula Calculate the Reynolds Number for liquid flow in a pipe Du Re= ρ ρ : fluid density D: pipe inside diameter µ u: average fluid velocity µ : viscosity Typical units and values kg lbm : 900 55 m ft D: 55 mm 2.09 in ρ 3 u: 3 m ft 2 5 µ : 0.005 Pa s s s 3cP 21 UserForms Insert a UserForm in the Visual Basic Editor (VBE) New and empty UserForm 22 11

UserForms change name and title Properties window lists properties of selected object, here the entire userform 23 UserForms Add title and field for density Add textbox for value change caption Properties window now refers to the label object 24 12

UserForms Add a frame to contain the units choices remove frame caption Add an option button in the frame for one units choice change title & caption stretch button so caption shows 25 UserForms change default button value to true add button for alternate units with caption and default false add similar entries for pipe diameter, velocity and viscosity 26 13

UserForms add a command button to compute the answer change command button name, caption & font 27 UserForms add a Quit button with similar formatting the UserForm is complete, but two important background elements are missing: 1) there is no way for the UserForm to appear for use 2) when the Compute and Quit buttons are clicked, nothing will happen there is no VBA code behind them We ll deal with 2) first. 28 14

UserForms double-click the Compute Re button here, we must add code to carry out the calculations necessary and display the Reynolds Number result convert units, as required compute the Reynolds Number and display the result 29 UserForms insert a new module and add this Sub to start the UserForm double-click the Quit button and add the code to remove ( unload ) the UserForm Run the StartReynoldsNumber macro and enter values with units selected 30 15

UserForms click the Compute Re button click OK then or 1) you can set up and compute other cases 2) you click the Quit button to close out the UserForm UserForms can be loaded automatically when the workbook is opened. This is called an event handler. And they can be unloaded automatically when the workbook is closed. Although this is a good example of the use of UserForms, there are many other options and possibilities. You may need a good VBA reference book to take advantage fully of the potential of UserForms. 31 16