expression.Delete
expression Required. An expression that returns one of the objects in the Applies To list.
Example
This Visual Basic for Applications (VBA) example uses the Delete method to delete the PersonalTasks folder within the Tasks folder. To run this example, you need to create a Tasks subfolder called PersonalTasks.
Sub DeleteTaskFolder()
Dim myolApp As New Outlook.Application
Dim oNamespace As Outlook.NameSpace
Dim oFolder As Outlook.MAPIFolder
Dim oOldFolder As Outlook.MAPIFolder
Dim strPrompt As String
Set oNamespace = myolApp.GetNamespace("MAPI")
Set oFolder = oNamespace.GetDefaultFolder(olFolderTasks)
Set oOldFolder = oFolder.Folders("PersonalTasks")
'Prompt the user for confirmation
strPrompt = "Are you sure you want to delete the folder?"
If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
oOldFolder.Delete
MsgBox ("Folder deleted")
End If
End Sub
If you use Microsoft Visual Basic Scripting Edition (VBScript) in a Microsoft Outlook form, you do not create the Application object, and you cannot use named constants. This example shows how to perform the same task using VBScript code.
Sub CommandButton1_Click()
Set oNameSpace = Application.GetNameSpace("MAPI")
Set oFolder = oNameSpace.GetDefaultFolder(13)
Set oOldFolder = oFolder.Folders("PersonalTasks")
'Prompt the user for confirmation
Dim strPrompt
strPrompt = "Are you sure you want to delete the folder?"
If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
oOldFolder.Delete
MsgBox("Folder deleted")
End If
End Sub