Thema Datum  Von Nutzer Rating
Antwort
12.01.2017 06:29:35 Dani
NotSolved
Blau Datei Anhand e-Mail
12.01.2017 08:51:22 SJ
NotSolved
13.01.2017 09:29:18 Dani
NotSolved
13.01.2017 16:41:22 SJ
NotSolved

Ansicht des Beitrags:
Von:
SJ
Datum:
12.01.2017 08:51:22
Views:
625
Rating: Antwort:
  Ja
Thema:
Datei Anhand e-Mail

Guten Morgen,

ich habe das Makro leicht angepasst, versuch das einmal:

Option Explicit

'Pfadkonstanten
Private Const FOLDER_PATH_1 As String = "C:\Users\hhwjanse\Desktop\tmp"
Private Const FOLDER_PATH_2 As String = "C:\Users\hhwjanse\Desktop\tmp\Neuer Ordner"
Private Const FILE_EXTENSION As String = "txt"

'Mailkonstanten
Private Const MAIL_TO As String = "test@domain.de"
Private Const MAIL_SUBJECT As String = "Test"
Private Const MAIL_BODYTEXT As String = "Testtext"

Public Sub create_mail()
    Dim strAttachment_1 As String, strAttachment_2 As String
    Dim appOut As New Outlook.Application
    Dim outMail As Outlook.MailItem
    
    strAttachment_1 = get_path_of_newest_file(FOLDER_PATH_1, FILE_EXTENSION)
    strAttachment_2 = get_path_of_newest_file(FOLDER_PATH_2, FILE_EXTENSION)
    
    Set outMail = appOut.CreateItem(olMailItem)
    
    With outMail
        .To = MAIL_TO
        .SUBJECT = MAIL_SUBJECT
        .Body = MAIL_BODYTEXT
        If Not strAttachment_1 = vbNullString Then .Attachments.Add strAttachment_1
        If Not strAttachment_2 = vbNullString Then .Attachments.Add strAttachment_2
        .Display
    End With
    
    Set outMail = Nothing
    Set appOut = Nothing
End Sub

Private Function get_path_of_newest_file(ByVal FolderPath As String, Optional ByVal FileExtension As String = vbNullString) As String
    Dim fso As New FileSystemObject
    Dim f As File, fTmp As File
    Dim strFilePath As String
    
    If fso.FolderExists(FolderPath) Then
        For Each f In fso.GetFolder(FolderPath).Files
            If Not FileExtension = vbNullString Then
                If fso.GetExtensionName(f.Path) = FileExtension Then
                    If fTmp Is Nothing Then
                        Set fTmp = f
                    Else
                        If f.DateLastModified > fTmp.DateLastModified Then
                            Set fTmp = f
                        End If
                    End If
                End If
            Else
                If fTmp Is Nothing Then
                    Set fTmp = f
                Else
                    If f.DateLastModified > fTmp.DateLastModified Then
                        Set fTmp = f
                    End If
                End If
            End If
        Next f
        strFilePath = fTmp.Path
    Else
        strFilePath = vbNullString
    End If
    
    get_path_of_newest_file = strFilePath
    
    Set f = Nothing
    Set fTmp = Nothing
    Set fso = Nothing
End Function

Wichtig: Es müssen 2 Verweise gesetzt werden (Extras -> Verweise):

  1. Microsoft Outlook xx.x Object Library
  2. Microsoft Scripting Runtime

Gruß


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
12.01.2017 06:29:35 Dani
NotSolved
Blau Datei Anhand e-Mail
12.01.2017 08:51:22 SJ
NotSolved
13.01.2017 09:29:18 Dani
NotSolved
13.01.2017 16:41:22 SJ
NotSolved