14 VBA - Visual Basic For Applications CEE3804 Computer...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
10/7/2004 Visual Basic For Applications 1 Visual Basic For Applications CEE3804 Computer Applications for Civil and Environmental Engineers
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
10/7/2004 Visual Basic For Applications 2 Topics to be Covered z Basics of VBA z Using code modules z Understanding procedures z Interacting with the user z Creating useful forms z Adjusting form layout z Using form and control events
Background image of page 2
10/7/2004 Visual Basic For Applications 3 VBA Basics Objects, Collections, and Object Models z Objects: z elements that represent some part of an application z workbook, chart, or form control z Collections: z a group of objects usually of the same type z group of workbooks Workbooks(1): the first workbook in a sequence of workbooks z Object Model: z a hierarchical representation of how the objects and collections are related to each other
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
10/7/2004 Visual Basic For Applications 4 VBA Basics Properties, Methods, and Arguments z z A property is an attribute of an object Example: color, font, size, value, etc. ActiveSheet.Name = “Data” z A method is an action an object can take Example: printing or copying Application.Quit or ActiveWorkbook.SaveAs “D:\test.xls” z Occasionally methods require information: z An argument is the information provided to the method Example: ActiveWorkbook.SaveAs “D:\test.xls or ActiveWorkbook.SaveAs Filename:= “D\test.xls
Background image of page 4
10/7/2004 Visual Basic For Applications 5 VBA Basics Arguments z Arguments can be provided in the exact order, or in any order where the argument is preceded by “:=“ z Example: ActiveWorkbook.SaveAs FileName:=“test.xls” z You can continue a line using the line- continuation character (_) z Example: ActiveWorkbook.SaveAs FileName:=“test.xls”, _ FileFormat:=xlExcel7
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
10/7/2004 Visual Basic For Applications 6 VBA Basics Object Libraries z The Object Library: z displays object libraries available to the current VBA project z press F2 to access the Object Library z three main areas: Search area Classes list Members list
Background image of page 6
10/7/2004 Visual Basic For Applications 7 VBA Basics VBA Projects and Components VBA creates a project for every open workbook contains all of the VBA code written and forms forms are custom dialog boxes that allow the user to input information code can be written in the code modules behind items z items include forms, textboxes, etc. code can be written in a standard module ideal for functions that will be shared
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
10/7/2004 Visual Basic For Applications 8 VBA Basics Organizing Code z Within any code module, code is grouped into distinct blocks known as procedures z A procedure: z contains one or more lines of code that accomplish a particular task z each line is a statement z blank lines are ignored z indent lines to make it easier to read the code z comments are preceded by colons
Background image of page 8
10/7/2004 Visual Basic For Applications 9 VBA Basics Using Code Modules z To insert a new standard module: z In the Visual Basic window
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 44

14 VBA - Visual Basic For Applications CEE3804 Computer...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online