MCQs > IT & Programming > VBA MCQs > Basic VBA MCQs

Basic VBA MCQ

1. A VBA project must declare four classes. How many class modules are needed?

Answer

Correct Answer: As many as are required by the variable types that the objects return

Note: This Question is unanswered, help us to find answer for this one

2. If VBA code declares FileCount as a constant rather than a variable, the code tends to run faster. Why is this?

Answer

Correct Answer: The Const declaraton specifies the most efficient type given the constant's value

Note: This Question is unanswered, help us to find answer for this one

3. To use VBA code to maintain a different VBA project, you can make use of VBA's extensibility. What is needed to enable extensibility?

Answer

Correct Answer: Include a reference to Microsoft VBA Extensibility 5.3

Note: This Question is unanswered, help us to find answer for this one

4. Which statement declares an array?

Answer

Correct Answer: Dim MyArray() As Array

Note: This Question is unanswered, help us to find answer for this one

5. When used with an array named MyArray, what is the preerred way to set beginning and ending values of a loop control variable?

Answer

Correct Answer: For i = LBound(MyArray,1) To UBound(MyArray,1)

Note: This Question is unanswered, help us to find answer for this one

6. What is needed for the contents of Module1 to be availble to other modules in a VBA project, but not to any other VBA project?

Answer

Correct Answer: Set Option Private Module at the top of Module1

Note: This Question is unanswered, help us to find answer for this one

7. How does a class module indicate that it uses a particular interface?

Answer

Correct Answer: The name of the interface is passed as a parameter.

Note: This Question is unanswered, help us to find answer for this one

8. When you define a new class of object, where do you assign a name to it?

Answer

Correct Answer: In a standard module's Properties

Note: This Question is unanswered, help us to find answer for this one

9. Which keyboard shortcut causes VBE to locate the declaration of a procedure?

Answer

Correct Answer: Shift+F2

Note: This Question is unanswered, help us to find answer for this one

10. Which action will cause your project to reset its variables?

Answer

Correct Answer: Click End in a run-time error dialog.

Note: This Question is unanswered, help us to find answer for this one

11. There are two references that must be selected in the Visual Basic Editor in order for any Visual Basic code to run in Excel. What are these two references?

Answer

Correct Answer: VBA and Excel object library

Note: This Question is unanswered, help us to find answer for this one

12. A declaration has scope, which has three levels. What are they?

Answer

Correct Answer: Procedure, Private Module and Public Module

Note: This Question is unanswered, help us to find answer for this one

13. Which statement is true?

Answer

Correct Answer: Let establishes a value in a class; Get returns a value from a class.

Note: This Question is unanswered, help us to find answer for this one

14. Which statement should precede a subroutuine's error handler?

Answer

Correct Answer: Exit Sub

Note: This Question is unanswered, help us to find answer for this one

15. The recording of a macro in Word is likely to be an incomplete record of the user's actions. Why?

Answer

Correct Answer: Word's Macro Recorder does not record actions that inlove selection of text by pointing with the mouse pointer.

Note: This Question is unanswered, help us to find answer for this one

16. Which variable name is valid in VBA?

Answer

Correct Answer: My_Var

Note: This Question is unanswered, help us to find answer for this one

17. Which cell is selected if you run this code Range("E3:312").Range("B3").Select

Answer

Correct Answer: F3

Note: This Question is unanswered, help us to find answer for this one

18. EmailAddress() is an array. It is declared by Dim EmailAddress(10) As String, and option Base 1 is in effect. How many rows and columns are in EmailAddress()?

Answer

Correct Answer: 10 rows and 1 column

Note: This Question is unanswered, help us to find answer for this one

19. You have several variables to display on a user form, and there are too many variables to display at once. Which control best enables the user to see all the variables?

Answer

Correct Answer: ListBox

Note: This Question is unanswered, help us to find answer for this one

20. What is the principal difference between a class and an object?

Answer

Correct Answer: A class describes the design of an object. An object is an instance of that design.

Note: This Question is unanswered, help us to find answer for this one

21. This code shows the first statement of CalledSub. Which calling statement will work properly? Sub CalledSub(Surname, Age)

Answer

Correct Answer: Calledsub

Note: This Question is unanswered, help us to find answer for this one

22. In the statement 'x = 400 * y', what is the maximum value that y can be if x has been declared as in Integer?

Answer

Correct Answer: 81

Note: This Question is unanswered, help us to find answer for this one

23. What is a Collection object?

Answer

Correct Answer: An ordered set of items

Note: This Question is unanswered, help us to find answer for this one

24. How can we declare a subroutine or function in VBA?

Answer

Correct Answer: Public, Private, Friend

Note: This Question is unanswered, help us to find answer for this one

25. To return the value of the Access database file's path, what VBA code will retrieve the value?

Answer

Correct Answer: CurDir

Note: This Question is unanswered, help us to find answer for this one

26. In order to prevent users from deleting database objects displayed in the Navigation Pane, what VBA code would be used?

Answer

Correct Answer: Docmd.LockNavigationPane True

Note: This Question is unanswered, help us to find answer for this one

27. To concatenate two lines of VBA code into one line, insert which character between the two joined lines?

Answer

Correct Answer: :

Note: This Question is unanswered, help us to find answer for this one

28. To create one array variable to store monthly mortgage rates over the course of a year, the following is the best declaration statement.

Answer

Correct Answer: Dim Rates(1 to 12) as Single

Note: This Question is unanswered, help us to find answer for this one

29. Choose the function used to send an table's contents in Excel format by email from Access.

Answer

Correct Answer: Docmd.SendObject(acSendTable, "tblEmployees", acFormatXLS, "Sally Moore;")

Note: This Question is unanswered, help us to find answer for this one

30. Choose the VBA code to allow you to obtain the value from Row 2 and Column 3 of a mutliple column listbox.

Answer

Correct Answer: Me.List0.Column(2,1)

Note: This Question is unanswered, help us to find answer for this one

31. To change the font color a textbox field, choose the VBA code that will allow you change the control's property.

Answer

Correct Answer: Me.Text11.ForeColor = vbRed

Note: This Question is unanswered, help us to find answer for this one

32. What reference will you add to add active x objects ,i.e. buttons, at runtime?

Answer

Correct Answer: Microsoft Visual Basic for Applications Extensibility Library

Note: This Question is unanswered, help us to find answer for this one

33. Which tools should be used to compile the program?

Answer

Correct Answer: Package & Deployment Wizard

Note: This Question is unanswered, help us to find answer for this one

34. What is the short cut to get Immediate Window

Answer

Correct Answer: Ctrl + G

Note: This Question is unanswered, help us to find answer for this one

35. Which of the following would NOT be a good use for a macro?

Answer

Correct Answer: Computing statistical calculations on data

Note: This Question is unanswered, help us to find answer for this one

36. Output of below code: Dim a As Integer Dim b As Integer a = 1000 b = 33 MsgBox a * b

Answer

Correct Answer: Run-time error '6': Overflow

Note: This Question is unanswered, help us to find answer for this one

37. To remove the records listed in a subform, which property and value would you need to add to your VBA code.

Answer

Correct Answer: RecordSource = ""

Note: This Question is unanswered, help us to find answer for this one

38. Out put of below code: Dim a As Single Dim b As Single a = 7 b = 2 MsgBox a / b & ", " & a \ b

Answer

Correct Answer: 3.5, 3

Note: This Question is unanswered, help us to find answer for this one

39. What is a result of this code? Sub Test() Dim myNumber As Double myNumber = -10.635 Debug.Print Fix(myNumber) Debug.Print Int(myNumber) End Sub

Answer

Correct Answer: -10 -11

Note: This Question is unanswered, help us to find answer for this one

40. Choose the VBA code used to close database and the Microsoft Access instance.

Answer

Correct Answer: Docmd.Quit

Note: This Question is unanswered, help us to find answer for this one

41. Choose the VBA code that will allow you to check to see if the form MainMenufrm is loaded.

Answer

Correct Answer: If CurrentProject.AllForms("MainMenufrm").IsLoaded Then

Note: This Question is unanswered, help us to find answer for this one

42. Without using SQL, choose the VBA code to allow you to delete the table Employees.

Answer

Correct Answer: CurrentDb.TableDefs.Delete "Employees"

Note: This Question is unanswered, help us to find answer for this one

43. The ____________ allow(s) for multiple controls in a user form, to execute the same sub.

Answer

Correct Answer: class module

Note: This Question is unanswered, help us to find answer for this one

44. Choose the VBA code that you would use to call a public function named VBAFunction from a form called FormA while passing a variant x1 in the module of FormB form. 

Answer

Correct Answer: Forms!FormA.VBAFunction(x1)

Note: This Question is unanswered, help us to find answer for this one

45. When you have added a new linked table using VBA code and it does not appear in Navigation Pane that displays the list of tables, forms, macros, and queries in the database.  Which VBA code would you use to update the list of database objects displayed in the Navigation Pane.

Answer

Correct Answer: Application.RefreshDatabaseWindow

Note: This Question is unanswered, help us to find answer for this one

46. What will Format(“A123”, “&&&&&&”) output?

Answer

Correct Answer: “A123”

Note: This Question is unanswered, help us to find answer for this one

47. Which is NOT a method of the Workspace object:

Answer

Correct Answer: Activate

Note: This Question is unanswered, help us to find answer for this one

48. You want to count how many records for a given customer based on CustomerID which is of field type short text in table tblCustomer. The customer id we want the count for is 123-AC. We are using the domain aggregate function DCount and assign it to an integer variable intC what is the correct syntax.

Answer

Correct Answer: intC = DCount ("*","tblCustomer","[CustomerID] = ' & 123-AC & "'")

Note: This Question is unanswered, help us to find answer for this one

49. Which function will allow you to convert a value to number?

Answer

Correct Answer: CLng

Note: This Question is unanswered, help us to find answer for this one

50. Where you can create you custom events?

Answer

Correct Answer: Classes and userforms but not in modules

Note: This Question is unanswered, help us to find answer for this one

51. You want to dump the values stored in a 12-element array named Rates into the cell range A1:A12.  How can you get that done?

Answer

Correct Answer: Range("A1:A12") = Application.WorksheetFunction.Transpose(Rates)

Note: This Question is unanswered, help us to find answer for this one

52. The application property that will assign a shortcut key to run a macro is:

Answer

Correct Answer: OnKey

Note: This Question is unanswered, help us to find answer for this one

53. Choose the VBA code that you would use to obtain the user login on a computer using a Windows operating system.

Answer

Correct Answer: Environ("Username")

Note: This Question is unanswered, help us to find answer for this one

54. Which Will Not display VBA code?

Answer

Correct Answer: VBA view

Note: This Question is unanswered, help us to find answer for this one

55. When integrating Excel, instead of adding a reference, which VBA code would you use to open Microsoft Excel.

Answer

Correct Answer: Set xlapp = CreateObject("Excel.Application")

Note: This Question is unanswered, help us to find answer for this one

56. Is it possible to expand storage space for dynamic Array variables with two or more dimensions, keeping the existing data?

Answer

Correct Answer: Yes, by changing the size of only the last dimension.

Note: This Question is unanswered, help us to find answer for this one

57. Choose the VBA code used to add a new record to the recordset xRec.

Answer

Correct Answer: xRec.AddNew

Note: This Question is unanswered, help us to find answer for this one

58. In Access, which VBA code will allow you to suppress alerts when deleting records from a table.

Answer

Correct Answer: DoCmd.SetWarnings False

Note: This Question is unanswered, help us to find answer for this one

59. True or False? An 'If-Then' statement must always be paired with an 'End If'.

Answer

Correct Answer: False

Note: This Question is unanswered, help us to find answer for this one

60. Which of the following snippets of VBA code will allow you to return the first array index in the array xItems?

Answer

Correct Answer: LBound(xItems)

Note: This Question is unanswered, help us to find answer for this one

61. Choose the VBA code to remove data from Row 2 in a multiple column listbox.

Answer

Correct Answer: Me.List0.RemoveItem 1

Note: This Question is unanswered, help us to find answer for this one

62. With out creating a reference to the Microsoft Scripting Runtime for the DLL to create a Dictionary object, choose the VBA code to allow you to do so.

Answer

Correct Answer: CreateObject("Scripting.Dictionary")

Note: This Question is unanswered, help us to find answer for this one

63. When integrating Excel, which VBA code will allow you transfer data from recordset xRec in Access directly onto a spreadsheet (xlws) in Excel.

Answer

Correct Answer: xlws.range("A1").CopyFromRecordset xRec

Note: This Question is unanswered, help us to find answer for this one

64. Choose the VBA code to execute a Word MailMerge in Access

Answer

Correct Answer: objWord.MailMerge.Execute

Note: This Question is unanswered, help us to find answer for this one

65. As an alternative to the If.. Then.. ElseIf..Else condition, how would you format the Choose function with variable x1 and the following conditions:  "Red", "Blue", "Yellow", "White"

Answer

Correct Answer: Choose(x1,"Red","Blue","Yellow","White")

Note: This Question is unanswered, help us to find answer for this one

66. What is BOF?

Answer

Correct Answer: A property of the Recordset object.

Note: This Question is unanswered, help us to find answer for this one

67. What is the difference between these commands CreateObject("Word.Application") GetObject(, "Word.Application")

Answer

Correct Answer: CreateObject always creates a new object. GetObject throws an error if no object of the class exists.

Note: This Question is unanswered, help us to find answer for this one

68. What is the right syntax to raise your custom error?

Answer

Correct Answer: Err.Raise Number:=999, Description:="My custom error"

Note: This Question is unanswered, help us to find answer for this one

69. Which is the correct way to use formulas on Excel in VBA code

Answer

Correct Answer: Using Worksheetfunction object

Note: This Question is unanswered, help us to find answer for this one

70. In the next statement: "Dim bValue as Boolean" What will be the default value for "bValue" variable?

Answer

Correct Answer: False

Note: This Question is unanswered, help us to find answer for this one

71. Under which menu option in the VBA IDE can you password protect a VBA project?

Answer

Correct Answer: Tools>VBAProject Properties

Note: This Question is unanswered, help us to find answer for this one

72. The library to make ADODB.connection work.

Answer

Correct Answer: Microsoft Active X Data Objects

Note: This Question is unanswered, help us to find answer for this one

73. You have written a function called Switch requiring the input string parameters a and b. The function will concatenate the values assigned to b and a, in that order. What line of code is needed within the function?

Answer

Correct Answer: Switch = b & a

Note: This Question is unanswered, help us to find answer for this one

74. Month(#12/25/02#) will output?

Answer

Correct Answer: 12

Note: This Question is unanswered, help us to find answer for this one

75. What will Format(2.36, “#0.0”) output?

Answer

Correct Answer: “2.4”

Note: This Question is unanswered, help us to find answer for this one

76. What value is x holding after this statement is executed: x = Left("Apple",3) & Right("People", 3)

Answer

Correct Answer: Appple

Note: This Question is unanswered, help us to find answer for this one

77. Choose the VBA code that will allow you to verify that an Item exists in the Dictionary object Dict1. 

Answer

Correct Answer: If xDict1.Exists("Testing") Then

Note: This Question is unanswered, help us to find answer for this one

78. When stepping through code as a way to see how the values in variables change, use the:

Answer

Correct Answer: Watch Window

Note: This Question is unanswered, help us to find answer for this one

79. Which code will allow user to edit a password protected worksheet.

Answer

Correct Answer: Sheets("Sheet1").Unprotect Password:="Password"

Note: This Question is unanswered, help us to find answer for this one

80. To change the text displayed in a label on a form, choose the VBA code that will allow you to update the property.

Answer

Correct Answer: Me.Label3.Caption = "Hello"

Note: This Question is unanswered, help us to find answer for this one

81. Combine into one line: If x > 5 Then y = x - 5 End If

Answer

Correct Answer: If x > 5 Then y = x - 5

Note: This Question is unanswered, help us to find answer for this one

82. To change a comment in cell A1, which will do the job?

Answer

Correct Answer: Range("A1").Comment.Text("My Comment")

Note: This Question is unanswered, help us to find answer for this one

83. What is the difference between activating and initializing a user form?

Answer

Correct Answer: Activate will always run when showing a user form whereas Initialize will only run when showing a user form that has not been stored in memory.

Note: This Question is unanswered, help us to find answer for this one

84. Which of the following actions will NOT cause a macro to run in Excel?

Answer

Correct Answer: (all of these will NOT cause a macro to run in Excel)

Note: This Question is unanswered, help us to find answer for this one

85. Choose the VBA code that switches control from the application to the OS.

Answer

Correct Answer: DoEvents

Note: This Question is unanswered, help us to find answer for this one

86. Which of the following functions do not perform a calculation

Answer

Correct Answer: Val

Note: This Question is unanswered, help us to find answer for this one

87. What is the property of a cell that allows you to set the font color of the contents?

Answer

Correct Answer: Font.Color

Note: This Question is unanswered, help us to find answer for this one

88. If you want to create a definition for a custom object in VBA, which of the following would be the best choice to insert into your project?

Answer

Correct Answer: Class Module

Note: This Question is unanswered, help us to find answer for this one

89. The statement 'Dim a, b as Single' declares the variables a and b as what variable types?

Answer

Correct Answer: a as Variant; b as Single

Note: This Question is unanswered, help us to find answer for this one

90. Dim a,b as integer What is the type of a?

Answer

Correct Answer: variant

Note: This Question is unanswered, help us to find answer for this one

91. Which of these statements will start a loop of exactly 20 iterations?

Answer

Correct Answer: For i = 2 to 40 Step 2

Note: This Question is unanswered, help us to find answer for this one

92. Which of the following VBA windows shows the code of the active object?

Answer

Correct Answer: Code window

Note: This Question is unanswered, help us to find answer for this one

93. The way to pass the latest values of variables between functions and procedures is identified as:

Answer

Correct Answer: ByRef

Note: This Question is unanswered, help us to find answer for this one

94. What is the shortcut keystroke to debug VBA code one line at a time?

Answer

Correct Answer: F8

Note: This Question is unanswered, help us to find answer for this one

95. In the statement x = "4" + "5"', x = ?

Answer

Correct Answer: 45

Note: This Question is unanswered, help us to find answer for this one

96. Which worksheet event can be used to run a procedure upon deleting the contents of a cell?

Answer

Correct Answer: Change

Note: This Question is unanswered, help us to find answer for this one

97. The RowSource property of a Combo Box control allows the user to:

Answer

Correct Answer: define the list of items, from a range of cells, to appear in a drop-down list

Note: This Question is unanswered, help us to find answer for this one

98. What does a VBA macro consist of?

Answer

Correct Answer: Computer code that performs some actions on or with objects

Note: This Question is unanswered, help us to find answer for this one

99. Declaring a public variable allows the user to..

Answer

Correct Answer: Use the variable anywhere in the project in which the variable was declared

Note: This Question is unanswered, help us to find answer for this one

100. Which of these is not a Visual Basic object?

Answer

Correct Answer: FontSize

Note: This Question is unanswered, help us to find answer for this one

101. Is it possible to create an array with the lowerbound being two?

Answer

Correct Answer: Yes

Note: This Question is unanswered, help us to find answer for this one

102. The shortcut keystroke to open the VBA IDE is:

Answer

Correct Answer: Alt+F11

Note: This Question is unanswered, help us to find answer for this one

103. You've created a user form named 'Entry_Form'. To make the user form appear, use which of the following statements?

Answer

Correct Answer: Entry_Form.Show

Note: This Question is unanswered, help us to find answer for this one

104. The tab order in a user form:

Answer

Correct Answer: ________ is a way to control the order in which the controls are selected using the TAB key.

Note: This Question is unanswered, help us to find answer for this one

105. Which of the following is not a VBA data type?

Answer

Correct Answer: VarChar

Note: This Question is unanswered, help us to find answer for this one

106. What do you need to select to set the developer mode?

Answer

Correct Answer: Show developer tab in the Ribbon

Note: This Question is unanswered, help us to find answer for this one

107. To continue to run code even if a line of code causes an error, choose the VBA code to continue to the next line of code.

Answer

Correct Answer: On Error Resume Next

Note: This Question is unanswered, help us to find answer for this one

108. True or False? Commenting at the end of a line of code is permissible.

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

109. True or False? It is possible to name a Sub with a string containing a space.

Answer

Correct Answer: False

Note: This Question is unanswered, help us to find answer for this one

110. To force all variables is a VBA project to be declared, which must be stated in a module?

Answer

Correct Answer: Option Explicit

Note: This Question is unanswered, help us to find answer for this one

111. On July 4, 2013, What will be displayed in the message box from the following statement: MsgBox(Format(Now,"mm-dd-yyyy"))

Answer

Correct Answer: 07-04-2013

Note: This Question is unanswered, help us to find answer for this one

112. How do you declare the variable myvar as an integer?

Answer

Correct Answer: Dim myvar As Integer

Note: This Question is unanswered, help us to find answer for this one

113. To comment a block of code, you must first:

Answer

Correct Answer: Activate the Edit toolbar in the Visual Basic Editor

Note: This Question is unanswered, help us to find answer for this one

114. You can use VBA to connect to a database in SQL Server using:

Answer

Correct Answer: an ADODB.Connection

Note: This Question is unanswered, help us to find answer for this one

115. What is a macro used for?

Answer

Correct Answer: To automatically complete a series of Excel steps

Note: This Question is unanswered, help us to find answer for this one

116. What is difference between a sub routine and a function.

Answer

Correct Answer: Function can return a value.

Note: This Question is unanswered, help us to find answer for this one

117. Which of the following do not work on Excel on Mac

Answer

Correct Answer: ActiveX Controls

Note: This Question is unanswered, help us to find answer for this one

118. To save a VBA project with an Excel workbook, the workbook must be saved as what type of file?

Answer

Correct Answer: xlsm

Note: This Question is unanswered, help us to find answer for this one

119. Correct this statement to start a 5-iteration loop: For x = 1 to 10 Step -2

Answer

Correct Answer: For x = 1 to 10 Step 2

Note: This Question is unanswered, help us to find answer for this one

120. How do you figure out the number of items in a collection?

Answer

Correct Answer: Using Count property

Note: This Question is unanswered, help us to find answer for this one

121. To obtain the value of the number of characters used in a textbox field on a form, which snippet of VBA code would you use?

Answer

Correct Answer: Len(CStr(Forms!DataEntryfrm.Text11.Value))

Note: This Question is unanswered, help us to find answer for this one

122. Using the Select Case construct is ideal when:

Answer

Correct Answer: A variable can take on multiple values

Note: This Question is unanswered, help us to find answer for this one

123. What does VBA mean?

Answer

Correct Answer: Visual Basic for Applications

Note: This Question is unanswered, help us to find answer for this one