18
Adding Automated Functionality to Office Applications

Adding Automated Functionality to Office Applications

  • Upload
    lyris

  • View
    29

  • Download
    0

Embed Size (px)

DESCRIPTION

Adding Automated Functionality to Office Applications. Macros. A macro is a or recorded and actions. With a single keystroke, users can play back these activities at a much faster speed than those same actions can be performed manually. - PowerPoint PPT Presentation

Citation preview

Page 1: Adding Automated Functionality to Office Applications

Adding Automated Functionality to Office Applications

Page 2: Adding Automated Functionality to Office Applications

Macros

• A macro is a or recorded and actions.

• With a single keystroke, users can play back these activities at a much faster speed than those same actions can be performed manually.

• Macros can help and the risk of error that typically occur when performing repetitive tasks.

Page 3: Adding Automated Functionality to Office Applications

Two different ways macros are created• K Macros– Perform a sequence of operations using keystrokes and

the mouse and the application records what you are doing

• W programming to accomplish a task.

• Both options use Visual Basic for Applications (VBA). The difference is how the VBA code is created

Page 4: Adding Automated Functionality to Office Applications

File tabSelect OPTIONS

Customize Ribbon ------ Select DEVELOPER as one of the main tabs

Page 5: Adding Automated Functionality to Office Applications

Recording 2 Macros

• First macro: Sum all columns

• Second macro– Sum all columns– Paste values into a Copy row– Deletes answer row (from first step)

Page 6: Adding Automated Functionality to Office Applications

Recording Macros• Benefits

– Q way to add automated functionality to your spreadsheet. The macro recorder simply records the keystrokes that you take or mouse actions that you perform

– Code is guaranteed to be free from syntax/coding errors– Can serve as a if you are inexperienced.

• Weaknesses– The macro recorder does not write the most efficient code. It records actions and

commands you might not need or want.– May have to record macro several times due to making errors in the recording

process. More chances for making errors.– If changes are made to the document (add column or row), the macro may not

function as intended. • Not as robust

– Works well for , but sometimes you want advanced functionality that recorded macros can’t make possible (button tasks)

Page 7: Adding Automated Functionality to Office Applications

Visual Basic for Applications (VBA)

Write programming code to accomplish a task.

Page 8: Adding Automated Functionality to Office Applications

• Visual Basic for Applications (VBA) is a programming language– VBA is a of – VBA requires a

• Excel, Access, PowerPoint, Word– You can customize an Excel workbook or enhance Access

database objects.• Create your own custom functions• Perform calculations using variables and constants• Create buttons that initiate process tasks (clicking button results

in something happening)• Display messages to users• Automate tasks rather than repeatedly doing something

Visual Basic for Applications (VBA)

Page 9: Adding Automated Functionality to Office Applications
Page 10: Adding Automated Functionality to Office Applications

• Procedures (also known as sub procedures or event procedures) are programming instructions that .

• Words in green are (not executable): apostrophe ‘comment

• Blue text signifies VBA keywords (reserved words) that have special meaning• Black text is regular text you have added• Indenting segments of code improves readability.

Page 11: Adding Automated Functionality to Office Applications

• VBA is an programming language: objects are created and then methods/actions are taken to manipulate to those objects.

• When a program is running, it needs to be able to accept input, perform calculations and then display output.

• I and boxes (located on a form or in an application) are used to obtain input for users while a program is running.

Page 12: Adding Automated Functionality to Office Applications

• Programs use constants and variables– Constants store values that– Variables store values that can while the

program is running.

• Data types– Use for alphanumeric data (letters, numbers, symbols)

– Use one of the numeric data types if the data will be used in a

Page 13: Adding Automated Functionality to Office Applications
Page 14: Adding Automated Functionality to Office Applications
Page 15: Adding Automated Functionality to Office Applications

• Typically, a computer program executes instructions sequentially ( ). This is called a sequence structure.

• However, there are two notable exceptions– D Structure

• A comparison is made, and based upon the results of the comparison, the program executes statements in a certain order– IF statements– IF…Then…Else statements (including ElseIf)– Select Case

– R Structure• Repeats the execution of certain statements while a certain condition is

true OR until a condition is true– For…Next– Loops

» Do While» Do Until

Page 16: Adding Automated Functionality to Office Applications

• I statements specify what should happen if a condition is true, but there is no alternative if the statement is false.

• IF…Then…Else statements specify what should happen if a condition is true and what should happen if a condition is false.• Just like our

Page 17: Adding Automated Functionality to Office Applications

Select Case

• Select Case allows you to test one value , and based upon the category

something is in, it returns the appropriate result.– This is much easier to create and understand than

nesting Ifs inside other Ifs.

Page 18: Adding Automated Functionality to Office Applications

Repetition Structures

• R the execution of statements while a certain condition is true OR until a condition is true• For…. statements

repeat execution a

• D repeat steps until something has happened or while something has not happened.• Do until or Do while