MS Outlook VBA Interview Questions and Answers with Examples

Home/100+ VBA Interview Questions and Answers with Examples/MS Outlook VBA Interview Questions and Answers with Examples

MS Outlook VBA Interview Questions and Answers with Examples

MS Outlook VBA Interview Questions and Answers explained with Example macros. Here are the list of most frequently asked basic MS Outlook VBA interview questions. All the questions are answered with simple examples. These questions will help you to answer basic questions to deal with MS Outlook VBA Programming/Development.

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates


Here is the following VBA procedure to create a new message using Outlook.

'Create a new message using Outlook
Sub Create_Message()
'Variable Declaration
Dim OLApp As New Outlook.Application
Dim oMessage As MailItem
'Create objects
Set OLApp = New Outlook.Application
Set oMessage = OLApp.CreateItem(olMailItem)
With oMessage
.To = ""
.Subject = "Test Email"
.Body = "This is a test message."
.Display
End With
Set objMail = Nothing
Set objOL = Nothing
End Sub
Here is the following VBA procedure to send a new message using Outlook

'Send a new message using Outlook
Sub Send_Message()
'Variable Declaration
Dim OLApp As New Outlook.Application
Dim oMessage As MailItem
'Create objects
Set OLApp = New Outlook.Application
Set oMessage = OLApp.CreateItem(olMailItem)
With oMessage
.To = ""
.Subject = "Test Email"
.Body = "This is a test message."
.Send
End With
Set objMail = Nothing
Set objOL = Nothing
End Sub
Here is the following VBA procedure to add attachment to a message using Outlook.

'Add attachment to a message using Outlook
Sub Add_Attachment_Message()
'Variable Declaration
Dim oMessage As Outlook.MailItem
Dim oAttachment As Outlook.Attachments
'Create Objects
Set oMessage = Application.CreateItem(olMailItem)
Set oAttachment = oMessage.Attachments
'Add attachment
oAttachment.Add "D:/Test.doc", olByValue, 1, "Test"
oMessage.Display
End Sub
Here is the following VBA procedure to add attachment and send a message using Outlook.

'Add attachment and send a message using Outlook
Sub Send_Message_With_Attachment()
'Variable Declaration
Dim oMessage As Outlook.MailItem
Dim oAttachment As Outlook.Attachments
'Create Objects
Set oMessage = Application.CreateItem(olMailItem)
Set oAttachment = oMessage.Attachments
'Add attachment
oAttachment.Add "D:/Test.doc", olByValue, 1, "Test"
'Add message details
With oMessage
.To = ""
.Subject = "Test Email"
.Body = "This is a test message."
.Send
End With
End Sub
Here is the following VBA procedure to create a Task in outlook.

Create a Task
Sub Create_Task()
'Variable Declaration
Dim Task As TaskItem
'Create object
Set myTask = Application.CreateItem(ItemType:=olTaskItem)
End Sub
Here is the following VBA procedure to delete completed tasks from a folder.

'Delete completed tasks from a folder
Sub Delete_Completed_Task()
'Variable Declaration
Dim oTask As Outlook.TaskItem
Dim oFolder As Outlook.Folder
'create object
Set oFolder = Outlook.Session.GetDefaultFolder(olFolderTasks)
'Loop through each task in a folder
For Each Task In oFolder.Items
'Create object
Set oTask = Task
'Check the status of the task is completed or not
If oTask.Status = olTaskComplete Then
'Delete completed task
oTask.delete
End If
Next
End Sub
Here is the following VBA procedure to create a folder in Outlook.

'Create a folder in Outlook
Sub Create_Folder()
Application.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks) _
.Folders.Add Name:="MyFolder", Type:=olFolderTasks
End Sub
Here is the following VBA procedure to delete a folder in Outlook.

'Delete a folder in Outlook
Sub Delete_Folder()
Application.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks) _
.Folders("MyFolder").delete
End Sub
Here is the following VBA procedure to create a new contact in Outlook.

'Create a new contact in Outlook
Sub Add_Contact()
'Variable Declaration
Dim oOutlook As Outlook.Application
Dim NewContact As ContactItem
'Create Objects
Set oOutlook = CreateObject("Outlook.Application")
Set NewContact = oOutlook.CreateItem(olContactItem)
'New Contact Details
With NewContact
.FirstName = "Analysis"
.LastName = "Tabs"
.Email1Address = ""
.Save
End With
End Sub
Here is the following VBA procedure to delete an existing contact in Outlook.

'Delete an existing contact in Outlook
Sub Delete_Contact()
'Variable Declaration
Dim oOutlook As Outlook.Application
Dim oInformation As NameSpace
Dim Contact As ContactItem
Dim eContacts As Items
'Create Objects
Set oOutlook = CreateObject("Outlook.Application")
Set oInformation = oOutlook.GetNamespace("MAPI")
Set eContacts = oInformation.GetDefaultFolder(olFolderContacts).Items
'Check for contact to delete from outlook contacts
For Each Contact In eContacts
If Contact.Email1Address = "" Then
Contact.delete
End If
Next
End Sub
Here is the following VBA procedure to delete Mail Items from a folder in Outlook.

'Delete Mail Items from a folder in Outlook
Sub Delete_Items()
'Variable Declaration
Dim oFolder As Outlook.Folder
Dim Cnt As Long
'Create Object
Set oFolder = Application.GetNamespace("MAPI"). _
GetDefaultFolder(olFolderDeletedItems)
'Loop through all items i
For Cnt = oFolder.Items.Count To 1 Step -1
oFolder.Items(Cnt).delete
Next
End Sub
Here is the following VBA procedure to get all Contact details in outlook.

'Get all Contact details in outlook
Sub Get_Contacts_From_Outlook()
'Variable declaration
Dim oContactsFolder As Folder
Dim oContact As ContactItem
'Create Object
Set oContactsFolder = Session.GetDefaultFolder(olFolderContacts)
'Loop through each contact in a contactfolder
For Each oContact In oContactsFolder.Items
'See contact details in immediate window
Debug.Print oContact.CompanyName
Next
'Display count of total contacts
MsgBox ("Total contacts Found : " & oContactsFolder.Items.Count)
End Sub

Here is the link for more VBA Interview Questions and Answers. These are explained for examples.
100+ VBA Interview Questions

LIMITED TIME OFFER

Related pages


how to record macro in excelproject estimation template exceldim i as integerhow do i unhide a column in excel 2010if statements in excel vbalistbox in vbvba code to import text file into excelexcel yearly schedule templateexcel vba repeatmacros tutorialarray in vba examplemacro to insert blank rows in excelcombine excel tabshow to copy columns to rows in excelexcel vba interiormacro to copy worksheetuse of concatenate in excelexcel vba sort rangemacro code for excelexcel formula if cell contains text thenhow to unhide all tabs in exceloops tricky interview questioncase statement vba accessprogress bar vba excelvba save excellearning excel macrosvb6 file existshiding tabs in excelmso file viewervba userform controlswriting an excel macroexcel vba manualmicrosoft excel 2007 exam questions and answersmake a drop down list in excel 2007hide excel sheet with passwordvba comment codehow to draw chart in excelvba file dialogactivate sheet vbams access mcq questions and answers pdfvba create fileexcel macro waitexcel graph in cellexcel vba odbc connection stringexcel macro change cell colorhow to remove protection from excel sheetmicrosoft excel quote templatehow to alphabetize in excel 2013vba functions in excelchange row height in excelmacros in excel 2007 for beginnersddl dml dcl tclshortcut key to change the sheet in excelworkbook close vbashortcut keys to excellistbox selectedvisual basic macros tutorialmultiple conditions in excelexcel vba returnapplication.goto referencehow do i unhide column amicrosoft excel create chartdrop down list excel 2007removing cells in excelvba checkboxexcel row widthhow to unhide column in excel 2007vba formsnested if in excel 2010drop down menu vbasas programming for dummiesembed forms combobox 1radio buttons excelpivot chart excel 2010 tutorialvba select worksheet