Thema Datum  Von Nutzer Rating
Antwort
03.07.2024 00:02:49 Kisska
Solved
Blau Mails in Ordner kopieren & verschieben - Makro optimieren
03.07.2024 00:06:50 Gast42158
NotSolved
03.07.2024 02:59:03 ralf_b
NotSolved
03.07.2024 10:53:10 Kisska
NotSolved
03.07.2024 11:47:20 ralf_b
*****
Solved
07.07.2024 17:06:43 Kisska
Solved

Ansicht des Beitrags:
Von:
Gast42158
Datum:
03.07.2024 00:06:50
Views:
89
Rating: Antwort:
  Ja
Thema:
Mails in Ordner kopieren & verschieben - Makro optimieren

Ich habe mich verschrieben, hier nochmal:

Makro 2: Funktioniert für mehrere markierte Mails

Sub CopyAndMoveEmails()
    Dim olApp As Outlook.Application
    Dim olNamespace As Outlook.NameSpace
    Dim olSelection As Outlook.Selection
    Dim destFolderName As String
    Dim destFolder As Outlook.folder
    Dim receivedFolder As Outlook.folder
    Dim mailItem As Object
    Dim i As Integer

    ' Initialize Outlook objects
    Set olApp = New Outlook.Application
    Set olNamespace = olApp.GetNamespace("MAPI")
    Set olSelection = olApp.ActiveExplorer.Selection

    ' Prompt user for destination folder name
    destFolderName = InputBox("Enter the name of the destination folder:", "Destination Folder")

    ' Check if user input is empty
    If destFolderName = "" Then
        MsgBox "No destination folder specified.", vbExclamation
        Exit Sub
    End If

    ' Find the destination folder
    Set destFolder = FindFolder(olNamespace.folders, destFolderName)

    If destFolder Is Nothing Then
        MsgBox "The destination folder """ & destFolderName & """ does not exist.", vbExclamation
        Exit Sub
    End If

    ' Find the "_01_erhalten" folder
    Set receivedFolder = FindFolder(olNamespace.folders, "_01_erhalten")

    If receivedFolder Is Nothing Then
        MsgBox "The folder ""_01_erhalten"" does not exist.", vbExclamation
        Exit Sub
    End If

    ' Process each selected email
    For i = 1 To olSelection.Count
        If TypeOf olSelection.Item(i) Is Outlook.mailItem Then
            Set mailItem = olSelection.Item(i)
            ' Copy the email to the destination folder
            On Error Resume Next
            mailItem.Copy.Move destFolder
            If Err.Number <> 0 Then
                MsgBox "Error copying email: " & Err.Description, vbExclamation
                Exit Sub
            End If
            On Error GoTo 0

            ' Move the original email to the "_01_erhalten" folder
            On Error Resume Next
            mailItem.Move receivedFolder
            If Err.Number <> 0 Then
                MsgBox "Error moving email: " & Err.Description, vbExclamation
                Exit Sub
            End If
            On Error GoTo 0
        End If
    Next i

    ' Display success message
    MsgBox "Emails copied to """ & destFolderName & """ and moved to ""_01_erhalten"" successfully.", vbInformation
End Sub

Function FindFolder(parentFolders As Outlook.folders, folderName As String) As Outlook.folder
    Dim folder As Outlook.folder
    Dim subFolder As Outlook.folder

    On Error Resume Next
    ' Iterate through each folder to find the matching folder
    For Each folder In parentFolders
        If folder.Name = folderName Then
            Set FindFolder = folder
            Exit Function
        Else
            Set subFolder = FindFolder(folder.folders, folderName)
            If Not subFolder Is Nothing Then
                Set FindFolder = subFolder
                Exit Function
            End If
        End If
    Next folder
    On Error GoTo 0

    ' If not found, return Nothing
    Set FindFolder = Nothing
End Function

 

VG, Kisska


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
03.07.2024 00:02:49 Kisska
Solved
Blau Mails in Ordner kopieren & verschieben - Makro optimieren
03.07.2024 00:06:50 Gast42158
NotSolved
03.07.2024 02:59:03 ralf_b
NotSolved
03.07.2024 10:53:10 Kisska
NotSolved
03.07.2024 11:47:20 ralf_b
*****
Solved
07.07.2024 17:06:43 Kisska
Solved