lindeunimog
Goto Top

Email Anhänge speichern VB Script aber nur bestimmte Dateitypen (Outlook)

Hallo,

Wir würden gerne nur bestimmte Email Anhänge speichern.

Mit diesem Script unten klappt es zwar ganz gut aber nicht perfekt.

Die Mitarbeiter möchten nur die PDF oder TXT Datei speichern die Sie erhalten und nicht die Firmenlogos in der Email.

Könntet ihr mir dabei bitte helfen. Danke für eure Mühe


Public Sub SaveAttachments()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem 'Object
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String

' Get the path to your My Documents folder
Dim enviro As String

enviro = CStr(Environ("%USERPROFILE%"))

strFolderpath = "Speicherort" & enviro
On Error Resume Next

' Instantiate an Outlook Application object.
Set objOL = CreateObject("Outlook.Application")

' Get the collection of selected objects.
Set objSelection = objOL.ActiveExplorer.Selection

' The attachment folder needs to exist
' You can change this to another folder name of your choice

' Set the Attachment folder.
strFolderpath = strFolderpath

' Check each selected item for attachments.
For Each objMsg In objSelection

Set objAttachments = objMsg.Attachments
lngCount = objAttachments.Count

If lngCount > 0 Then

' Use a count down loop for removing items
' from a collection. Otherwise, the loop counter gets
' confused and only every other item is removed.

For i = lngCount To 1 Step -1

' Get the file name.
strFile = objAttachments.Item(i).FileName

' Combine with the path to the Temp folder.
strFile = strFolderpath & strFile

' Save the attachment as a file.
objAttachments.Item(i).SaveAsFile strFile

Next i
End If

Next

ExitSub:

Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub

Content-Key: 319644

Url: https://administrator.de/contentid/319644

Ausgedruckt am: 19.03.2024 um 10:03 Uhr

Mitglied: 131339
Lösung 131339 31.10.2016 aktualisiert um 15:33:48 Uhr
Goto Top
Im Scriptkopf:
Set fso = CreateObject("Scripting.FileSystemObject")  
und um den Savebefehl eine If-Abfrage
if LCase(fso.GetExtensionName(strFile)) = "pdf" or LCase(fso.GetExtensionName(strFile)) = "txt" then  
    objAttachments.Item(i).SaveAsFile strFile
End if 
Schluckauf
Mitglied: LindeUnimog
LindeUnimog 31.10.2016 um 15:40:30 Uhr
Goto Top
Danke für die schnelle Antwort.

Script läuft ohne Fehler durch aber er wirft mit weiterhin die kompletten Emailanhänge aus.
Mitglied: 131339
Lösung 131339 31.10.2016 aktualisiert um 15:42:56 Uhr
Goto Top
Dann hast dus falsch umgesetzt! und den alten Save-Befehl ohne die IF-Abfrage drin gelassen :-P.
Mitglied: LindeUnimog
LindeUnimog 31.10.2016 um 16:16:16 Uhr
Goto Top
Genau das war es

Top Danke dir / ihnen