Lynda: Up and Running With VBA In Excel Flashcards
What does a programming language need to enable? (four things)?
- Accept Input
- Store Data
- Manipulate Data
- Produce Output
What are the three elements of an object in an Object-Oriented Programming Language?
- Properties
- Methods
- Events
What are some examples of common objets in Excel VBA?
- Application
- Workbook
- Worksheet
What are examples of properties in a workbook object in Excel VBA?
- Name
- Sheets
- Saved
What are some examples of methods for a workbook object in Excel VBA?
- Close
- PrintOut
- Save
What are some examples of Events for a workbook object in Excel VBA?
- BeforeClose
- NewSheet
- BeforeSave
What are some examples of properties for a Worksheet object in Excel VBA?
- Name
- UsedRange
- Visible
What are some examples of methods for a Worksheet object in Excel VBA?
- Activate
- Copy
- Delete
What are some examples of Events for a Worksheet object in Excel VBA?
- Activate
- Deactivate
- Change
Where can you find a list of all objects and their properties in Excel?
In the VBA window, look for the “Object Browser”
How do you create a new function in VBA? Example (sales Tax)?
In the project window enter “function instead of Sub, and then name it your function (all caps to match existing functions), then parentheses to define inputs and outside parentheses to define output
Example:
Function SALESTAX(curSales As Currency, dblRate As Double), As Double
SALESTAX = dblRate * curSales
End Function
Why should you make most of your Subroutines “Private”? How?
Most “Subs” should be “Private” unless they absolutely need to be accessible from other workbooks, such as a general use conditional subroutine, etc. Otherwise someone might accidentally use the macro on their workbook and cause disastrous results. You can make a “Sub” private by putting “Private” in front of it so it looks like “Private Sub”. This will prevent it from being accessed in other workbooks.
How do you add effective comments to your VBA code?
First comment should be your name, and when the code was created
Next should be a description of what the code does, and the workbook name, in case someone copies it elsewhere
What are data types in Excel VBA? Examples? How can you find a list of them all?
Data types are categories which limit the options of a variable to save memory and load faster when completing complex operations
Examples: Byte has to be between 0 and 255 and must be an integer. Boolean can only be True or False
Go to “Help” and type “Data type Summary” in the search, then click on the article that comes up
What does “Dim” stand for in VBA? Why is it used?
Dim stands for Dimension
It is used at the top of your code to define a variable as a certain data type to save memory.