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


left in vbaaddition in columns worksheets3d surface plot excelcopy excel sheet to another workbookvba is emptyadvanced excel vba examplesvba application inputboxmacros function in exceltutorial on excel pivot tablestranspose excel vbacompile excel vbahow to create a excel worksheetvba macros in excel 2007msgbox hello worldmacro loop exceldml and ddl statementsexcel 2010 remove duplicate rowscreate bar chart in excel 2010learn vba codevb.net excel saveasexcel check duplicate formulavba do loopshow to copy and paste excel sheetexcel check boxmacro tutorial excelhow to delete duplicates from excelhow to use countifs in excelsample vba projectsdynamic charts in excel 2007excel saveas fileformathow to title columns in excelexcel hide cellexample of worksheet in excelexcel if statement greater than or equal toexcel function substitutesample gantt chart templatecode execution has been interrupted excel vbaexcel vba columns functionexcel advanced filter formulavba code for yes no message boxexcel vba application waitexcel vba pivotexcel vba worksheetchart title excel 2010vlookup with choose functionvba redim preserve arrayexcel vba usesunprotect workbook excel 2010 without passwordselect sheet vbasort worksheets alphabeticallyexcel project management templatesvlookup between two valuessyntax excel definitionunprotect excel onlinexml to excel convertervba examvb6 listbox columnscombobox vba excel userformexcel advanced filter date rangeexcel programming tutorialsmsgbox input vbac programming interview questions answers and explanationsexcel add ins freewareexcel lookup formulaexcel 2010 name managerform control vs activex controlexcel background color formulaexcel dedupevba excel textboxexcel unprotect sheet commandusing vlookup in excel 2007excel formula to find duplicates in a listexcel sum if formula