MCAS Macros & Automation 2 — Questions and Answers
Question 1: Which object in VBA refers to the currently active workbook in Excel?
- ThisWorkbook
- ActiveWorkbook (Correct answer)
- CurrentWorkbook
- OpenWorkbook
Correct answer: ActiveWorkbook
ActiveWorkbook refers to the workbook that currently has focus, while ThisWorkbook refers to the workbook containing the code.
Question 2: What VBA statement is used to display a message box to the user?
- InputBox
- MsgBox (Correct answer)
- Alert
- ShowMessage
Correct answer: MsgBox
MsgBox is the VBA function used to display a pop-up message box to the user.
Question 3: In a VBA macro, which loop structure repeats a block of code a specific number of times?
- Do While...Loop
- For...Next (Correct answer)
- Do Until...Loop
- While...Wend
Correct answer: For...Next
The For...Next loop iterates a set number of times using a counter variable.
Question 4: How can a macro be assigned to a button in an Excel worksheet?
- Right-click the button and select 'Assign Macro' (Correct answer)
- Double-click the button in the ribbon
- Use File > Options > Macros
- Drag the macro name onto the button
Correct answer: Right-click the button and select 'Assign Macro'
Right-clicking a form control button and selecting 'Assign Macro' links a recorded or written macro to that button.
Question 5: Which Excel Quick Access Toolbar customization allows you to run a macro with one click?
- Adding a macro command to the QAT via File > Options > Quick Access Toolbar (Correct answer)
- Dragging the macro from the Formulas tab
- Pinning the macro in the Review tab
- Using Format Cells to link the macro
Correct answer: Adding a macro command to the QAT via File > Options > Quick Access Toolbar
You can add a macro as a custom button on the Quick Access Toolbar through File > Options > Quick Access Toolbar.
Question 6: What is the purpose of the 'Option Explicit' statement at the top of a VBA module?
- It enables macro recording
- It requires all variables to be declared before use (Correct answer)
- It sets the macro security level
- It exports the module to a file
Correct answer: It requires all variables to be declared before use
Option Explicit forces the developer to declare all variables, reducing errors from typos in variable names.
Question 7: In VBA, which keyword is used to declare a variable?
- Set
- Dim (Correct answer)
- Let
- Var
Correct answer: Dim
The 'Dim' keyword (short for Dimension) is used in VBA to declare a variable and its data type.
Which object in VBA refers to the currently active workbook in Excel?