Create outlook folder automatically (or delete)

linkaiyi
Follow

create or delete outlook folder from excel list

delete folder

Option Explicit

Public Sub MoveSelectedMessages()
    Dim objParentFolder As Outlook.Folder
    Dim newFolderName As String
    Dim strFilepath

    Dim xlApp As Object 'Excel.Application
    Dim xlWkb As Object 'As Workbook
    Dim xlSht As Object 'As Worksheet
    Dim rng As Object 'Range

    Set xlApp = CreateObject("Excel.Application")

    strFilepath = xlApp.GetOpenFilename
    If strFilepath = False Then
        xlApp.Quit
        Set xlApp = Nothing
        Exit Sub
    End If

    Set xlWkb = xlApp.Workbooks.Open(strFilepath)
    Set xlSht = xlWkb.Worksheets(1)
    Dim iRow As Integer

    iRow = 2

Set objParentFolder = Application.ActiveExplorer.CurrentFolder

While xlSht.Cells(iRow, 1) <> ""
newFolderName = xlSht.Cells(iRow, 1)

On Error Resume Next

Dim objNewFolder As Outlook.Folder
Dim schulungen As Outlook.Folder
Dim website As Outlook.Folder
Set objNewFolder = objParentFolder.Folders(newFolderName)

If Not objNewFolder Is Nothing Then
    objNewFolder.Delete
End If

    iRow = iRow + 1

  Set objNewFolder = Nothing
Wend

    xlWkb.Close
    xlApp.Quit
    Set xlWkb = Nothing
    Set xlApp = Nothing
    Set objParentFolder = Nothing
End Sub

‘ comment in VBA

create folder

If objNewFolder Is Nothing Then
    Set objNewFolder = objParentFolder.Folders.Add(newFolderName)
    Set schulungen = objNewFolder.Folders.Add("Schulungen")
    Set website = objNewFolder.Folders.Add("Website Audit")
End If
Object has 0 attachments

Was this article helpful?

This article is viewed 65 times!

Related Articles

0 Comments

Leave a Comment

Support