using visual basic for applications in microsoft project sean vogel

17
Using Visual Basic for Applications in Microsoft Project Sean Vogel

Upload: coral-conley

Post on 03-Jan-2016

218 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Using Visual Basic for Applications in Microsoft Project Sean Vogel

Using Visual Basic for Applications in Microsoft Project

Sean Vogel

Page 2: Using Visual Basic for Applications in Microsoft Project Sean Vogel

Why VBA?

• Automate repetitive tasks– Save time– Reduce error– Impress your neighbor

• Calculate metrics on schedules instantly

• Customize Interfaces

Page 3: Using Visual Basic for Applications in Microsoft Project Sean Vogel

VB Editor is located under the tools menu, macros, VB editor. This is true for every office product.

Orientation to the Visual Basic Editor

Page 4: Using Visual Basic for Applications in Microsoft Project Sean Vogel

PropertiesWindow

Watch Window – used in troubleshooting

Main screen – used for code

Debug toolbar

Orientation to the Visual Basic Editor

Project Explorer

Page 5: Using Visual Basic for Applications in Microsoft Project Sean Vogel

Object BrowserGives you every possible variable for each Office product

Orientation to the Visual Basic Editor

Page 6: Using Visual Basic for Applications in Microsoft Project Sean Vogel

Orientation to the Visual Basic Editor

To control other applications you must first install the references. In the VB Editor go to the tools menu, select references. Scroll down until you find the application you want.

Page 7: Using Visual Basic for Applications in Microsoft Project Sean Vogel

Programming 101

• Definition Section

– Define variables used in the code

• String – used for text

• Array – used to store data in 1,2,3 or more dimensional tables

• Boolean – true/false, used to check conditions

• Long – used to store numbers

• Code section

– Sequential order of what should happen (like building a house)

• Pour foundation

• Build Walls

• Build Roof

• Charge way to much for it

– Flowchart or map out any complex ideas prior to coding

Page 8: Using Visual Basic for Applications in Microsoft Project Sean Vogel

Programming 101

• 4 most used code statements

– If Statement

IF you want lunch THEN

give me money

ELSE

keep your money

END IF

– Select Statement

SELECT CASE color

CASE = “red”

X = 1

CASE = “blue”

X = 2

END SELECT

Page 9: Using Visual Basic for Applications in Microsoft Project Sean Vogel

Programming 101

• 4 most used code statements (cont)

– While Statement

WHILE leave = false

do this

do this

do this

WEND

– For Statement

FOR = 1 to 10

write array(y)

NEXT y

Page 10: Using Visual Basic for Applications in Microsoft Project Sean Vogel

Define the Variables

Page 11: Using Visual Basic for Applications in Microsoft Project Sean Vogel

Write the code to count tasks the late starts, off baseline tasks, and task dependencies

Use this If statement to find the date that will determine if the task is late.

This is the basic For Next statement we will use to loop through every task in the project. We will paste our other code within this statement.

Page 12: Using Visual Basic for Applications in Microsoft Project Sean Vogel

Write the code to count tasks the late starts, off baseline tasks, and task dependencies

These IF Statements check for late starts or tasks that are off their baselines.

See how we nest a For Next statement to check for task dependencies within each task.

Page 13: Using Visual Basic for Applications in Microsoft Project Sean Vogel

Write the Excel File

This statement checks if Excel is already open. If Excel is already open you don’t want to open a second instance. We set the isrunning Boolean to true or false depending on if it is running. We will use this later.

Page 14: Using Visual Basic for Applications in Microsoft Project Sean Vogel

Write the Excel File

Writing things to Excel requires you to use X/Y coordinates to determine the exact cell you want to modify.

The first slot is for the row index, the second for the column.

These last two lines auto size the columns for better format.

Page 15: Using Visual Basic for Applications in Microsoft Project Sean Vogel

Write the Excel File

Now that the summary page is written let’s write the late and off baseline tasks. We must first change to another sheet.

We will then use a For Next statement to write the task information.

Page 16: Using Visual Basic for Applications in Microsoft Project Sean Vogel

Write the Excel File

We will now write the last tab with Off Baseline Task data.

Page 17: Using Visual Basic for Applications in Microsoft Project Sean Vogel

Final StepsLast, we will save the file and close Excel