VBA session 3 Paul Rubinov  My job: diverse audience so Bore you for 15 minutes. Confuse you for the other 15 min.  Feel free to contact me

Slides:



Advertisements
Similar presentations
Lecture 4 Basic Scripting. Administrative  Files on the website will be posted in pdf for compatibility  Website is now mirrored at:
Advertisements

Creating New Financial Statements In Excel Presented by: Nancy Ross.
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.
Using Macros and Visual Basic for Applications (VBA) with Excel
Tutorial 8: Developing an Excel Application
Creating a Program In today’s lesson we will look at: what programming is different types of programs how we create a program installing an IDE to get.
Microsoft Excel 2003 Illustrated Complete with Excel Programming.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
How to Debug VB .NET Code.
Using the Visual Basic Editor Visual Basic for Applications 1.
Lecture Excel: Multiple Worksheets. Workbook and Worksheets Multiple worksheets in a single workbook. When saved, only a single workbook (XLS) is saved.
Microsoft Access 2007 Microsoft Access 2007 Introduction to Database Programs.
By Andrew Noske My PowerPoint Macros.
DEMONSTRATION FOR SIGMA DATA ACQUISITION MODULES Tempatron Ltd Data Measurements Division Darwin Close Reading RG2 0TB UK T : +44 (0) F :
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
Christopher Guertin VAMC – West Palm Beach, FL 1.
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 VBA. What is VBA? VBA stands for Visual Basic for Applications. It is a programming language used exclusively by the Microsoft Office.
Objectives Define what a Macro is
Week 1.  Kate Watson  Checked at least every other day. Queries and general comments welcome.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #2: The Visual Basic Editor The Visual Basic for Applications Programming Language IE 212: Computational.
Introduction to Excel VBA University of Chicago Graduate School of Business Introduction to Computer Based Models Bus Mr. Schrage Spring 2003.
1 Programming Concepts Module Code : CMV6107 Class Contact Hours: 45 hours (Lecture 15 hours) (Laboratory/Tutorial 30 hours) Module Value: 1 Textbook:
Languages and Environments Higher Computing Unit 2 – Software Development.
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.
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...
Microsoft Excel Macros & Excel Solver (IENG490)
Introduction on VBA Lab 05 ins.Tahani Al_dweesh. Lab Objectives Introduction Calculation with VBA Storing and Retrieving Variables in a Worksheet Using.
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
Microsoft Office 2003: Advanced 1 ADVANCED MICROSOFT ACCESS Lesson 17 – Utilizing Advanced Management Tools.
Chapter 11: Introduction to the Visual Basic Environment Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Introduction to Matlab & Data Analysis
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
‘Tirgul’ # 7 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #7.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with MSSQL Server Code:G0-C# Version: 1.0 Author: Pham Trung Hai CTD.
Your compuBase online services Module 5: Extract Data.
Just as there are many human languages, there are many computer programming languages that can be used to develop software. Some are named after people,
Visual Basic for Applications Macro Programming For Microsoft Office.
OCC Network Drives  H:\  P:\ 
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
Bob Angstadt Example of a “Front Panel” (Control) Spreadsheet Bob Angstadt May 4, 2004.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”
Introduction to VB.NET 2005 Dr. McDaniel IDS4704 Spring 2005.
Chapter 3 The Visual Basic Editor. Important Features of the VBE Alt-F11 will open the Visual Basic Editor. The Code window is to the right, Project Explorer.
Creating Macros in Excel Adding Automated Functionality to Excel & Office Applications.
Introduction to Python Lesson 1 First Program. Learning Outcomes In this lesson the student will: 1.Learn some important facts about PC’s 2.Learn how.
Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Spreadsheets Lesson 2 Introduction to basic formula and spreadsheet.
Intermacs Form Download Excel Tutorial Pivot Tables, Graphic Tools, Macros By: Devin Koehl.
Introduction to Excel VBA UNC Charlotte CPE/PDH Series December 17, 2009.
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft® Excel 2013.
Introduction to OOP in VB.NET using Robots ACSE Conference, Nov 2004 Michael Devoy Monsignor Doyle C.S.S., Cambridge
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
Introduction to Microsoft Excel Macros COE 201- Computer Proficiency.
Intermacs Form Download Excel Tutorial Pivot Tables, Graphic Tools, Macros By: Devin Koehl.
Introduction to: Python and OpenSesame FOR PROS. OpenSesame In OpenSesame you can add Python in-line codes which enables complex experiment. We will go.
Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.
Software Development Languages and Environments. Computer Languages Just as there are many human languages, there are many computer programming languages.
Introduction to Computers

Outline In this module, the following topics will be covered:
Learning Excel Session 9 and 10 Dr. Chaitali Basu Mukherji.
Introduction to Computers
Tonga Institute of Higher Education
Our Environment We will exercise on Microsoft Visual C++ v.6
Introduction to Database Programs
Presentation transcript:

VBA session 3 Paul Rubinov  My job: diverse audience so Bore you for 15 minutes. Confuse you for the other 15 min.  Feel free to contact me  Disclaimer IANAP (I am not a programmer) We are not covering language syntax – but your book does

VBA session 3: Introduction  When we programmed in Pascal or C or Fortran, we wrote what we needed. In VBA (and VB), you try to find the “thing” (object/control) that does what you want.  Key to learning VBA is knowing that something CAN be done. Record lots of macros. Give yourself a project.

VBA session 3: Intro cont.  Must have skills: record macros and play with them! use the help system (F1)! use step/step into: F8/SHIFT-F8 break points and watches: F9, SHIFT+F9 print stuff: “debug.print” and CTRL+G (remember you can also change variables in the “immediate” window) copy others people code! If you master these skills, you are 90% done

VBA session 3: Intro cont.  Type some numbers  Type some formulas  Play with formatting  Add a plot  Etc. …but do it on your own time. For now, open Example1.xls

VBA session 3: Example1  VBA has a very rich syntax - too rich. It has a lot of history… 1.Open example1.xls 2.Press Alt-F11 3.Double click on “Module1” 4.Put cursor anywhere after “sub” 5.Press Ctrl-G 6.Press F8- and keep pressing!

VBA session 3: Example1 cont.  Now double click on “module2”  By now you are used to x.y.z but notice this line: Selection.AutoFill Destination:=Range("C1:C3"),Type:=xlFillDefault This is using “named parameters”  Put your cursor anywhere inside the word “AutoFill” and press F1*. so no big deal- this is just a function call *If you get an error message when you try this, you do not have help installed for VBA. It is not installed by default!

VBA session 3: Stepper  The “stepper” (/”looper”) open “skeleton_stepper.xls” This is a “simulated” stepper to demo the idea (inspired by Bob A’s “listproc”. Only “modMain” is relevant but feel free to click around Idea : save parameters in excel rows: one row=1 step run many events with each parameter “step” display summary results on screen/store detail in file, if needed

VBA session 3: Stepper cont.  Comments: not meant for use by other people, but…  Basic instruction: press the RUN button Main sheet is called… “MAIN” Column A:“Step #”: cell A7 should be 1, cell A8=2, etc. if the last number in this column is 1, it will loop if any number is 0, it will stop Column B: “Evnt/step”: number of “events” per step- should be > 0

VBA session 3: Stepper cont.  Basic instruction (cont.): Column C: “Some parameter”: an example… adjusts the average- should be 5 to 15 Column F: progress report: number for successes/number of tries Column H and the following 63 columns: random data, standard distribution with StdDev = 10 and mean = 10*”Some parameter” Sheet “Profile”: simple histograms, always accumulating

VBA session 3: Random examples  This is all from the “Stepper” to find, press CTRL-F in VBA, make sure ”Current Project” radio button is pressed and search for the highlighted word Ex1: calling windows DLLs Public Declare Function timeGetTime Lib "winmm.dll" () As Long Declare Sub Sleep Lib "Kernel32.DLL" (ByVal dwMillisecconds As Long)

VBA session 3: examples cont. Ex2: If you have a driver for Visual Basic, chances are, it will work in VBA ScopeLibrary module (search for Hewlett-Packard ) VBIB/NIGLOBAL modules (search for GPIB ) Ex3: Example of Bob A’s utility routines Search for: XUTIL.DLL Ex4: Example of Bob A’s routines for performance Search for: MCMUTIL.DLL

VBA session 3: examples cont. Ex5: You can see an example of the use of STATIC variables in module Search for: Static NumEvts This module is used in the skeleton version of the stepper, so you should be able to debug it, see how it works.

VBA session 3: examples cont. Ex6: You can create your own objects by defining a new “Class” Search for: “Class_Initialize” This is also an example of using an external “object” (in this case the “Scripting” class) And also an example of file access using the FileSystem object contained in the scripting library

VBA session 3: Conclusion  VBA is the essence of RAD: Rapid Application Development or in English Easy tool for Quick and Dirty software jobs  If you have a PC on your desk or lab bench you can do more/faster with VBA

VBA session 3: Resources  Microsoft is the mothership: you may wish to Start Here  also try here or herehere  is a good place to start searching for all kinds of interfaces  Here are some fun FAQsFAQs  A good place to learn about VB is herehere  Did you know there is a free version of VB? It’s true: look herehere