VBA (Visual Basic for Applications) Interview Questions
This section covers frequently asked VBA interview questions.
1. What are Macros in VBA?
Macros are automated sequences of actions or instructions written in VBA (Visual Basic for Applications). They're used to automate repetitive tasks, saving time and improving efficiency.
2. Basic Excel Object Model.
The Excel object model represents Excel's objects in a hierarchical structure: Application
-> Workbooks
-> Worksheets
-> Range
/Chart
.
3. Opening the VBA Editor.
Use the keyboard shortcut Alt+F11
.
4. Option Explicit
.
Option Explicit
forces you to explicitly declare all variables in VBA, reducing errors and making code easier to maintain.
5. Core Modules in the VBA Editor.
- Standard Modules: Contain functions and procedures.
- UserForms: For creating user interfaces.
- Class Modules: For defining custom classes and objects.
6. Automating Worksheet Open.
Use the Workbook_Open()
event to run a macro automatically when a workbook opens.
Example
Private Sub Workbook_Open()
MsgBox "Workbook opened!", vbInformation
End Sub
7. Scope Levels of Variables.
- Local: Declared within a procedure or function.
- Module-level: Declared at the module level; accessible within the module.
- Global-level: Declared using
Public
; accessible throughout the project.
8. Creating Object Variables.
Example
Dim wb As Workbook
Set wb = ActiveWorkbook
9. Arrays in VBA.
Arrays store collections of values of the same data type.
Syntax
Dim myArray(10) As Integer 'Creates an array with 11 elements (index 0 to 10)
10. Stopping Macro Recording.
(This section describes how to stop macro recording in the VBA editor.)
11. Deleting Macros.
(This section describes how to delete macros from an Excel workbook using the VBA editor.)
12. Speeding Up VBA Macros.
- Avoid using
Variant
data types. - Turn off
ScreenUpdating
. - Turn off automatic calculations.
- Disable events.
- Use
With
statements. - Use
vbNullString
instead of""
. - Release object variables using
Set obj = Nothing
.
13. Built-in VBA Class Modules.
(This section would list built-in class modules like Workbook
, Worksheet
, etc.)
Microsoft Access VBA Interview Questions
1. Creating a Table in MS Access (VBA).
VBA Code
Sub CreateTable()
CurrentDb.Execute "CREATE TABLE MyTable (FieldName TEXT);"
End Sub
2. Inserting Records in MS Access (VBA).
VBA Code
Sub InsertRecord()
CurrentDb.Execute "INSERT INTO MyTable (FieldName) VALUES ('Some Value');"
End Sub
3. Updating Records in MS Access (VBA).
VBA Code
Sub UpdateRecord()
CurrentDb.Execute "UPDATE MyTable SET FieldName = 'NewValue' WHERE AnotherField = 'SomeValue';"
End Sub
4. Deleting Records in MS Access (VBA).
VBA Code
Sub DeleteRecord()
CurrentDb.Execute "DELETE FROM MyTable WHERE FieldName = 'SomeValue';"
End Sub
5. Exporting an Access Table to Excel (VBA).
VBA Code
Sub ExportTableToExcel()
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "MyTable", "C:\path\to\excelFile.xlsx", True
End Sub
6. Renaming a Table in MS Access (VBA).
VBA Code
Sub RenameTable()
DoCmd.Rename "OldTableName", acTable, "NewTableName"
End Sub
Microsoft Word VBA Interview Questions
1. Opening a New Word Document.
VBA Code
Sub OpenNewDocument()
Documents.Add
End Sub
2. Opening a New Document from an Existing Document.
VBA Code
Sub OpenNewDocFromExisting()
Documents.Add(Visible:=True) 'Adjust Visible as needed
End Sub
13. Why Use Breakpoints in SSIS (Repeated from earlier section)?
Breakpoints temporarily halt execution at a specific point in an SSIS package allowing for inspection and debugging.
14. Checkpoints in SSIS (Repeated from earlier section).
Checkpoints enable restarting a package from a previously saved point in case of failure, minimizing reprocessing.
15. Containers That Don't Save Checkpoint Data (Repeated from earlier section).
Loop containers (For Loop and For Each Loop) don't save checkpoint data.
16. Variable Types in SSIS (Repeated from earlier section).
Global and task-specific variables are used in SSIS packages for storing and managing data within the process.
17. Connection Managers in SSIS (Repeated from earlier section).
Connection managers establish connections to databases and other data sources.
18. Lookup Cache Modes (Repeated from earlier section).
Full Cache, Partial Cache, and No Cache modes control how lookup transformations access and store data during processing.
19. Deploying SSIS Packages (Repeated from earlier section).
Deployment involves moving packages to a server environment or other executable storage location.
20. Logging SSIS Executions (Repeated from earlier section).
SSIS allows logging to various destinations (like text files and SQL Server) to help track operations.
21. Common SSIS Errors (Repeated from earlier section).
(This section would list common errors that might occur in SSIS packages.)
22. Workflows in SSIS (Repeated from earlier section).
Workflows define the execution order of tasks and containers in an SSIS package.
23. Data Profiling Task (Repeated from earlier section).
Data profiling helps analyze data characteristics to inform design decisions.
24. Ignore Failure Option (Repeated from earlier section).
Allows the package to continue running if a task fails.
25. Event Logging Mode (Repeated from earlier section).
Controls whether logging is enabled: Enabled, Disabled, or inherit from parent.
26. Stopping Running SSIS Packages (Repeated from earlier section).
(This section would discuss the methods for stopping SSIS packages running in different environments.)
27. Supported File Formats and Connections (Repeated from earlier section).
(This section lists the file formats and database connection types supported by SSIS.)
Microsoft Word VBA Interview Questions.
1. Creating a New Word Document.
VBA Code
Sub CreateWordDocument()
Documents.Add
End Sub
2. Opening a New Document from an Existing Document.
VBA Code
Sub OpenNewDocumentFromExisting()
Documents.Add
End Sub
3. Opening an Existing Document as Read-Only.
VBA Code
Sub OpenReadOnlyDocument()
Documents.Open FileName:= "C:\path\to\document.docx",ReadOnly:=True
End Sub
4. SavingAs a Word Document.
VBA Code
Sub SaveAsWordDocument()
ActiveDocument.SaveAs FileName:= "C:\path\to\document.docx"
End Sub
5. Selecting the Current Line.
VBA Code
Sub SelectCurrentLine()
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
End Sub
6. Selecting the Entire Document.
VBA Code
Sub SelectEntireDocument()
Selection.WholeStory
End Sub
7. Changing Paragraph Font Size.
VBA Code
Sub ChangeFontSize()
ActiveDocument.Paragraphs(3).Range.Font.Size = 13
End Sub