Outlook - Ordner im Postein- und Postausgang erstellen...

Outlook - Ordner im Posteingang und Postausgang erstellen. Wie geht das?

Create a folder in your Inbox and Outbox - Outlook. How does it work?

Option Explicit
'--------------------------------------------------------------------------
' Module    : Modul1
' Procedure : Main
' Author    : Case (Ralf Stolzenburg)
' Date      : 18.01.2016
' Purpose   : Outlook - Ordner unter Postein- und Postausgang erstellen...
'--------------------------------------------------------------------------
Sub Main()
    Dim objNewFolder As Object
    Dim varFolder As Variant
    Dim objFolder As Object
    Dim objOutApp As Object
    Dim objName As Object
    Dim blnTMP As Boolean
    On Error GoTo Fin
    varFolder = Application.InputBox("Ordnername?", Type:=2)
    If Not varFolder = False And Trim(varFolder) <> "" Then
        Set objOutApp = CreateObject("Outlook.Application")
        Set objName = objOutApp.GetNamespace("MAPI")
        ' 6 = olFolderInbox
        ' 4 = olFolderOutbox
        On Error Resume Next
        Set objFolder = objName.GetDefaultFolder(6)
        Set objNewFolder = objFolder.Folders.Add(varFolder)
        If Err.Number = 440 Then blnTMP = True
        Err.Clear
        On Error GoTo Fin
        Set objFolder = objName.GetDefaultFolder(4)
        Set objNewFolder = objFolder.Folders.Add(varFolder)
    End If
Fin:
    Select Case Err.Number
        Case 440
            MsgBox "Ordner bereits vorhanden!"
        Case 0
        Case Else
            MsgBox "Fehler: " & Err.Number & " " & Err.Description
    End Select
    Set objNewFolder = Nothing
    Set objFolder = Nothing
    Set objName = Nothing
    Set objOutApp = Nothing
End Sub
' Nachfolgend die Elemente bzw. Konstanten von "OlDefaultFolders"
' Entnommen aus Objektkatalog (F2 im VBA-Editor) in Outlook 2010
'Const olFolderCalendar = 9
'Const olFolderConflicts = 19 (&H13)
'Const olFolderContacts = 10
'Const olFolderDeletedItems = 3
'Const olFolderDrafts = 16 (&H10)
'Const olFolderInbox = 6
'Const olFolderJournal = 11
'Const olFolderJunk = 23 (&H17)
'Const olFolderLocalFailures = 21 (&H15)
'Const olFolderManagedEmail = 29 (&H1D)
'Const olFolderNotes = 12
'Const olFolderOutbox = 4
'Const olFolderRssFeeds = 25 (&H19)
'Const olFolderSentMail = 5
'Const olFolderServerFailures = 22 (&H16)
'Const olFolderSuggestedContacts = 30 (&H1E)
'Const olFolderSyncIssues = 20 (&H14)
'Const olFolderTasks = 13
'Const olFolderToDo = 28 (&H1C)
'Const olPublicFoldersAllPublicFolders = 18 (&H12)

Kommentare

Beliebte Posts aus diesem Blog

Formeln - auch Array - per VBA eintragen...

Alle Dateien eines Ordners - Optional mit Unterordner

Excel -> Word in Textmarken (Bookmarks)...