Μετάβαση στο κύριο περιεχόμενο

Πώς να αποθηκεύσετε όλα τα συνημμένα από πολλά email σε φάκελο στο Outlook;

Είναι εύκολο να αποθηκεύσετε όλα τα συνημμένα από ένα email με την ενσωματωμένη δυνατότητα Αποθήκευση όλων των συνημμένων στο Outlook. Ωστόσο, εάν θέλετε να αποθηκεύσετε όλα τα συνημμένα από πολλά email ταυτόχρονα, δεν υπάρχει άμεση δυνατότητα που μπορεί να σας βοηθήσει. Πρέπει να εφαρμόσετε επανειλημμένα τη δυνατότητα Αποθήκευση όλων των συνημμένων σε κάθε μήνυμα ηλεκτρονικού ταχυδρομείου έως ότου αποθηκευτούν όλα τα συνημμένα από αυτά τα μηνύματα ηλεκτρονικού ταχυδρομείου. Αυτό είναι χρονοβόρο. Σε αυτό το άρθρο, παρουσιάζουμε δύο μεθόδους για να αποθηκεύσετε μαζικά όλα τα συνημμένα από πολλά μηνύματα ηλεκτρονικού ταχυδρομείου σε έναν συγκεκριμένο φάκελο εύκολα στο Outlook.

Αποθηκεύστε όλα τα συνημμένα από πολλά email σε φάκελο με κώδικα VBA
Αρκετά κλικ για αποθήκευση όλων των συνημμένων από πολλά μηνύματα ηλεκτρονικού ταχυδρομείου σε φάκελο με ένα καταπληκτικό εργαλείο


Αποθηκεύστε όλα τα συνημμένα από πολλά email σε φάκελο με κώδικα VBA

Αυτή η ενότητα παρουσιάζει έναν κώδικα VBA σε έναν οδηγό βήμα προς βήμα για να σας βοηθήσει να αποθηκεύσετε γρήγορα όλα τα συνημμένα από πολλά μηνύματα ηλεκτρονικού ταχυδρομείου σε έναν συγκεκριμένο φάκελο ταυτόχρονα. Κάντε τα εξής:

1. Πρώτον, πρέπει να δημιουργήσετε ένα φάκελο για την αποθήκευση των συνημμένων στον υπολογιστή σας.

Μπείτε στο έγγραφα φάκελο και δημιουργήστε ένα φάκελο με το όνομα "Συνημμένα". Δείτε screenshot:

2. Επιλέξτε τα email που θα αποθηκεύσετε τα συνημμένα και, στη συνέχεια, πατήστε άλλος + F11 για να ανοίξετε το Microsoft Visual Basic για εφαρμογές παράθυρο.

3. κλικ Κύριο θέμα > Μονάδα μέτρησης για να ανοίξετε το Μονάδα μέτρησης παράθυρο και, στη συνέχεια, αντιγράψτε έναν από τους ακόλουθους κωδικούς VBA στο παράθυρο.

Κωδικός VBA 1: Μαζική αποθήκευση συνημμένων από πολλαπλά μηνύματα ηλεκτρονικού ταχυδρομείου (αποθήκευση απευθείας συνημμένων με το ίδιο όνομα)

Συμβουλές: Αυτός ο κωδικός θα αποθηκεύσει τα ίδια συνημμένα ονόματα προσθέτοντας ψηφία 1, 2, 3 ... μετά τα ονόματα αρχείων.

Dim GCount As Integer
Dim GFilepath As String
Public Sub SaveAttachments()
'Update 20200821
Dim xMailItem As Outlook.MailItem
Dim xAttachments As Outlook.Attachments
Dim xSelection As Outlook.Selection
Dim i As Long
Dim xAttCount As Long
Dim xFilePath As String, xFolderPath As String, xSaveFiles As String
On Error Resume Next
xFolderPath = CreateObject("WScript.Shell").SpecialFolders(16)
Set xSelection = Outlook.Application.ActiveExplorer.Selection
xFolderPath = xFolderPath & "\Attachments\"
If VBA.Dir(xFolderPath, vbDirectory) = vbNullString Then
    VBA.MkDir xFolderPath
End If
GFilepath = ""
For Each xMailItem In xSelection
    Set xAttachments = xMailItem.Attachments
    xAttCount = xAttachments.Count
    xSaveFiles = ""
    If xAttCount > 0 Then
        For i = xAttCount To 1 Step -1
            GCount = 0
            xFilePath = xFolderPath & xAttachments.Item(i).FileName
            GFilepath = xFilePath
            xFilePath = FileRename(xFilePath)
            If IsEmbeddedAttachment(xAttachments.Item(i)) = False Then
                xAttachments.Item(i).SaveAsFile xFilePath
                If xMailItem.BodyFormat <> olFormatHTML Then
                    xSaveFiles = xSaveFiles & vbCrLf & "<Error! Hyperlink reference not valid.>"
                Else
                    xSaveFiles = xSaveFiles & "<br>" & "<a href='file://" & xFilePath & "'>" & xFilePath & "</a>"
                End If
            End If
        Next i
    End If
Next
Set xAttachments = Nothing
Set xMailItem = Nothing
Set xSelection = Nothing
End Sub

Function FileRename(FilePath As String) As String
Dim xPath As String
Dim xFso As FileSystemObject
On Error Resume Next
Set xFso = CreateObject("Scripting.FileSystemObject")
xPath = FilePath
FileRename = xPath
If xFso.FileExists(xPath) Then
    GCount = GCount + 1
    xPath = xFso.GetParentFolderName(GFilepath) & "\" & xFso.GetBaseName(GFilepath) & " " & GCount & "." + xFso.GetExtensionName(GFilepath)
    FileRename = FileRename(xPath)
End If
xFso = Nothing
End Function

Function IsEmbeddedAttachment(Attach As Attachment)
Dim xItem As MailItem
Dim xCid As String
Dim xID As String
Dim xHtml As String
On Error Resume Next
IsEmbeddedAttachment = False
Set xItem = Attach.Parent
If xItem.BodyFormat <> olFormatHTML Then Exit Function
xCid = ""
xCid = Attach.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F")
If xCid <> "" Then
    xHtml = xItem.HTMLBody
    xID = "cid:" & xCid
    If InStr(xHtml, xID) > 0 Then
        IsEmbeddedAttachment = True
    End If
End If
End Function
Κωδικός VBA 2: Μαζική αποθήκευση συνημμένων από πολλά μηνύματα ηλεκτρονικού ταχυδρομείου (ελέγξτε για διπλότυπα)
Public Sub SaveAttachments()
'Update 20200821
Dim xMailItem As Outlook.MailItem
Dim xAttachments As Outlook.Attachments
Dim xSelection As Outlook.Selection
Dim i As Long
Dim xAttCount As Long
Dim xFilePath As String, xFolderPath As String, xSaveFiles As String
Dim xYesNo As Integer
Dim xFlag As Boolean
On Error Resume Next
xFolderPath = CreateObject("WScript.Shell").SpecialFolders(16)
Set xSelection = Outlook.Application.ActiveExplorer.Selection
xFolderPath = xFolderPath & "\Attachments\"
If VBA.Dir(xFolderPath, vbDirectory) = vbNullString Then
    VBA.MkDir xFolderPath
End If
For Each xMailItem In xSelection
    Set xAttachments = xMailItem.Attachments
    xAttCount = xAttachments.Count
    xSaveFiles = ""
    If xAttCount > 0 Then
        For i = xAttCount To 1 Step -1
            xFilePath = xFolderPath & xAttachments.Item(i).FileName
            xFlag = True
            If VBA.Dir(xFilePath, 16) <> Empty Then
                xYesNo = MsgBox("The file is exists, do you want to replace it", vbYesNo + vbInformation, "Kutools for Outlook")
                If xYesNo = vbNo Then xFlag = False
            End If
            If xFlag = True Then
                xAttachments.Item(i).SaveAsFile xFilePath
                If xMailItem.BodyFormat <> olFormatHTML Then
                    xSaveFiles = xSaveFiles & vbCrLf & "<Error! Hyperlink reference not valid.>"
                Else
                    xSaveFiles = xSaveFiles & "<br>" & "<a href='file://" & xFilePath & "'>" & xFilePath & "</a>"
                End If
            End If
        Next i
    End If
Next
Set xAttachments = Nothing
Set xMailItem = Nothing
Set xSelection = Nothing
End Sub

Notes:

1) Εάν θέλετε να αποθηκεύσετε όλα τα συνημμένα ονόματα σε ένα φάκελο, εφαρμόστε τα παραπάνω Κωδικός VBA 1. Πριν εκτελέσετε αυτόν τον κωδικό, κάντε κλικ Εργαλεία > αναφορές, και στη συνέχεια ελέγξτε το Χρόνος εκτέλεσης δέσμης ενεργειών Microsoft στο πλαίσιο Αναφορές - Έργο κουτί διαλόγου;

doc αποθήκευση συνημμένων07

2) Εάν θέλετε να ελέγξετε για διπλά ονόματα συνημμένων, εφαρμόστε τον κωδικό VBA 2. Μετά την εκτέλεση του κώδικα, θα εμφανιστεί ένα παράθυρο διαλόγου για να σας υπενθυμίσει εάν θα αντικαταστήσετε τα διπλά συνημμένα, επιλέξτε Ναι or Οχι με βάση τις ανάγκες σας.

5. Πάτα το F5 κλειδί για την εκτέλεση του κώδικα.

Στη συνέχεια, όλα τα συνημμένα σε επιλεγμένα email αποθηκεύονται στο φάκελο που δημιουργήσατε στο βήμα 1. 

: Μπορεί να υπάρχει Microsoft Outlook αναδυόμενο πλαίσιο, κάντε κλικ στο Επιτρέψτε κουμπί για να προχωρήσετε.


Αποθηκεύστε όλα τα συνημμένα από πολλά email σε φάκελο με ένα καταπληκτικό εργαλείο

Εάν είστε αρχάριος στο VBA, συνιστάται εδώ Αποθήκευση όλων των συνημμένων χρησιμότητα του Kutools για το Outook για σενα. Με αυτό το βοηθητικό πρόγραμμα, μπορείτε να αποθηκεύσετε γρήγορα όλα τα συνημμένα από πολλά email ταυτόχρονα με αρκετά κλικ μόνο στο Outlook.
Πριν εφαρμόσετε τη λειτουργία, παρακαλώ κατεβάστε και εγκαταστήστε πρώτα το Kutools για Outlook.

1. Επιλέξτε τα email που περιέχουν τα συνημμένα που θέλετε να αποθηκεύσετε.

Συμβουλές: Μπορείτε να επιλέξετε πολλαπλά μηνύματα ηλεκτρονικού ταχυδρομείου δίπλα στο κουμπί Ctrl κλειδί και επιλέξτε τα ένα προς ένα.
Ή επιλέξτε πολλά παρακείμενα μηνύματα ηλεκτρονικού ταχυδρομείου κρατώντας το αλλαγή και επιλέξτε το πρώτο email και το τελευταίο.

2. κλικ Kutools >Εργαλεία συνημμένουΑποθήκευση όλων. Δείτε το στιγμιότυπο οθόνης:

3. Στο Αποθήκευση ρυθμίσεων , κάντε κλικ στο για να επιλέξετε ένα φάκελο για να αποθηκεύσετε τα συνημμένα και, στη συνέχεια, κάντε κλικ στο OK κουμπί.

3. κλικ OK δύο φορές στο επόμενο αναδυόμενο παράθυρο διαλόγου, Στη συνέχεια, όλα τα συνημμένα σε επιλεγμένα email αποθηκεύονται ταυτόχρονα στον καθορισμένο φάκελο.

:

  • 1. Εάν θέλετε να αποθηκεύσετε συνημμένα σε διαφορετικούς φακέλους βάσει μηνυμάτων ηλεκτρονικού ταχυδρομείου, ελέγξτε το Δημιουργήστε υποφακέλους με το ακόλουθο στυλ και επιλέξτε ένα στυλ φακέλου από το αναπτυσσόμενο μενού.
  • 2. Εκτός από την αποθήκευση όλων των συνημμένων, μπορείτε να αποθηκεύσετε συνημμένα με συγκεκριμένες συνθήκες. Για παράδειγμα, θέλετε να αποθηκεύσετε μόνο τα συνημμένα αρχεία pdf στα οποία το όνομα αρχείου περιέχει τη λέξη "Τιμολόγιο", κάντε κλικ στο Επιλογές για προχωρημένους για να επεκτείνετε τις συνθήκες και, στη συνέχεια, ρυθμίστε τις παραμέτρους όπως φαίνεται στο παρακάτω screebshot.
  • 3. Εάν θέλετε να αποθηκεύσετε αυτόματα συνημμένα κατά την άφιξη του email, το Αυτόματη αποθήκευση συνημμένων δυνατότητα μπορεί να βοηθήσει.
  • 4. Για την αποσύνδεση των συνημμένων απευθείας από επιλεγμένα email, το Αποσύνδεση όλων των συνημμένων χαρακτηριστικό του Kutools για το Outlook μπορεί να σας κάνει μια χάρη.

  Εάν θέλετε να έχετε μια δωρεάν δοκιμή (60-ημερών) αυτού του βοηθητικού προγράμματος, κάντε κλικ για να το κατεβάσετεκαι μετά πηγαίνετε για να εφαρμόσετε τη λειτουργία σύμφωνα με τα παραπάνω βήματα.


Σχετικά Άρθρα

Εισαγάγετε συνημμένα στο σώμα του μηνύματος email στο Outlook
Κανονικά, τα συνημμένα εμφανίζονται στο συνημμένο πεδίο σε ένα σύνθετο email. Εδώ αυτό το σεμινάριο παρέχει μεθόδους που θα σας βοηθήσουν να εισαγάγετε εύκολα συνημμένα στο σώμα email στο Outlook.

Αυτόματη λήψη / αποθήκευση συνημμένων από το Outlook σε έναν συγκεκριμένο φάκελο
Σε γενικές γραμμές, μπορείτε να αποθηκεύσετε όλα τα συνημμένα ενός email κάνοντας κλικ στα Συνημμένα> Αποθήκευση όλων των συνημμένων στο Outlook. Αλλά, εάν πρέπει να αποθηκεύσετε όλα τα συνημμένα από όλα τα ληφθέντα μηνύματα ηλεκτρονικού ταχυδρομείου και να λάβετε μηνύματα ηλεκτρονικού ταχυδρομείου, είναι ιδανικό; Αυτό το άρθρο θα εισαγάγει δύο λύσεις για αυτόματη λήψη συνημμένων από το Outlook σε έναν συγκεκριμένο φάκελο.

Εκτυπώστε όλα τα συνημμένα σε ένα / πολλαπλά μηνύματα ηλεκτρονικού ταχυδρομείου στο Outlook
Όπως γνωρίζετε, θα εκτυπώνει το περιεχόμενο email μόνο όπως κεφαλίδα, σώμα όταν κάνετε κλικ στο Αρχείο> Εκτύπωση στο Microsoft Outlook, αλλά δεν εκτυπώνει τα συνημμένα. Εδώ θα σας δείξουμε πώς να εκτυπώνετε άνετα όλα τα συνημμένα σε ένα επιλεγμένο email στο Microsoft Outlook.

Αναζήτηση λέξεων εντός συνημμένου (περιεχομένου) στο Outlook
Όταν πληκτρολογούμε μια λέξη-κλειδί στο πλαίσιο Άμεσης αναζήτησης στο Outlook, θα αναζητήσει τη λέξη-κλειδί στα θέματα των μηνυμάτων ηλεκτρονικού ταχυδρομείου, στα σώματα, στα συνημμένα κ.λπ. Αυτό το άρθρο σάς δείχνει τα λεπτομερή βήματα για εύκολη αναζήτηση λέξεων εντός περιεχομένου συνημμένων στο Outlook.

Διατηρήστε συνημμένα κατά την απάντηση στο Outlook
Όταν προωθούμε ένα μήνυμα email στο Microsoft Outlook, τα αρχικά συνημμένα σε αυτό το μήνυμα email παραμένουν στο προωθημένο μήνυμα. Ωστόσο, όταν απαντάμε σε ένα μήνυμα ηλεκτρονικού ταχυδρομείου, τα αρχικά συνημμένα δεν θα επισυνάπτονται στο νέο μήνυμα απάντησης. Εδώ θα παρουσιάσουμε μερικά κόλπα σχετικά με τη διατήρηση των αρχικών συνημμένων κατά την απάντηση στο Microsoft Outlook.


Τα καλύτερα εργαλεία παραγωγικότητας γραφείου

Kutools για το Outlook - Πάνω από 100 ισχυρές δυνατότητες για υπερφόρτιση του Outlook σας

🤖 Βοηθός αλληλογραφίας AI: Άμεσα επαγγελματικά email με μαγεία AI -- με ένα κλικ για ιδιοφυείς απαντήσεις, τέλειος τόνος, πολυγλωσσική γνώση. Μεταμορφώστε τα email χωρίς κόπο! ...

📧 Αυτοματοποίηση ηλεκτρονικού ταχυδρομείου: Εκτός γραφείου (Διαθέσιμο για POP και IMAP)  /  Προγραμματισμός αποστολής email  /  Αυτόματο CC/BCC βάσει κανόνων κατά την αποστολή email  /  Αυτόματη προώθηση (Σύνθετοι κανόνες)   /  Αυτόματη προσθήκη χαιρετισμού   /  Διαχωρίστε αυτόματα τα μηνύματα ηλεκτρονικού ταχυδρομείου πολλών παραληπτών σε μεμονωμένα μηνύματα ...

📨 Διαχείριση e-mail: Εύκολη ανάκληση email  /  Αποκλεισμός απάτης email από υποκείμενα και άλλους  /  Διαγραφή διπλότυπων μηνυμάτων ηλεκτρονικού ταχυδρομείου  /  Προχωρημένη Αναζήτηση  /  Ενοποίηση φακέλων ...

📁 Συνημμένα ProΜαζική αποθήκευση  /  Αποσύνδεση παρτίδας  /  Συμπίεση παρτίδας  /  Αυτόματη αποθήκευση   /  Αυτόματη απόσπαση  /  Αυτόματη συμπίεση ...

🌟 Διασύνδεση Magic: 😊Περισσότερα όμορφα και δροσερά emojis   /  Ενισχύστε την παραγωγικότητά σας στο Outlook με προβολές με καρτέλες  /  Ελαχιστοποιήστε το Outlook αντί να κλείσετε ...

???? Με ένα κλικ Wonders: Απάντηση σε όλους με εισερχόμενα συνημμένα  /   Email κατά του phishing  /  🕘Εμφάνιση ζώνης ώρας αποστολέα ...

👩🏼‍🤝‍👩🏻 Επαφές & Ημερολόγιο: Μαζική προσθήκη επαφών από επιλεγμένα μηνύματα ηλεκτρονικού ταχυδρομείου  /  Διαχωρίστε μια ομάδα επαφής σε μεμονωμένες ομάδες  /  Κατάργηση υπενθυμίσεων γενεθλίων ...

Διανεμήθηκαν παραπάνω από 100 Χαρακτηριστικά Περιμένετε την εξερεύνηση σας! Κάντε κλικ εδώ για να ανακαλύψετε περισσότερα.

 

 

Comments (81)
Rated 3.5 out of 5 · 3 ratings
This comment was minimized by the moderator on the site
Thank you for sharing the code. Unfortunately, I tried both with failure. This is what I got - The macros in this project are disabled. Please refer to the online help or documentation of the host application to determine how to enable macros. Thank you.
This comment was minimized by the moderator on the site
Hi,
Please follow the instructions in the screenshot below to check if macros are enabled in the macro settings in your Outlook. After enabling both options, re-run the VBA code.

https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/macro-enabled.png
This comment was minimized by the moderator on the site
Thank you so much.
Rated 5 out of 5
This comment was minimized by the moderator on the site
Thank you for sharing VBA code. This work like magic and is going to save it lots of time!
This comment was minimized by the moderator on the site
Hello friends!

Thanks for sharing this VBA code.

Is there any way to change the location of the save folder?

I share the pc with some colleagues and in this case I need the files to be saved in a password protected folder which is not located in the documents folder.

How can I make this change?

Thank you in advance
This comment was minimized by the moderator on the site
Hi Fabiana,
Change the line 14
xFolderPath = xFolderPath & "\Attachments\"

to
xFolderPath = "C:\Users\Win10x64Test\Desktop\save attachments\1\"

Here "C:\Users\Win10x64Test\Desktop\save attachments\1\" is the folder path in my case.
Don't forget to end the folder path with a slash "\"
This comment was minimized by the moderator on the site
Hello friends!

Thank you for sharing that VBA code.

Is there any way to change the location of the save folder?

I share the pc with some colleagues and in this case I need the files to be saved in a password protected folder which is not located in the documents folder.

How can I make this change?

Thank you in advance
This comment was minimized by the moderator on the site
If you are trying to run the Code that renames duplicate files and keep getting a "User Type Not Defined" error message here is the code fixed. Instead of the "Dim xFso As FileSystemObject" on line 47 it should be "Dim xFso As Variant"
Also added a Message Box to appear at the end of data transfer.

Dim GCount As Integer
Dim GFilepath As String
Public Sub SaveAttachments()
'Update 20200821
Dim xMailItem As Outlook.MailItem
Dim xAttachments As Outlook.Attachments
Dim xSelection As Outlook.Selection
Dim i As Long
Dim xAttCount As Long
Dim xFilePath As String, xFolderPath As String, xSaveFiles As String
On Error Resume Next
xFolderPath = CreateObject("WScript.Shell").SpecialFolders(16)
Set xSelection = Outlook.Application.ActiveExplorer.Selection
xFolderPath = xFolderPath & "\Attachments\"
If VBA.Dir(xFolderPath, vbDirectory) = vbNullString Then
VBA.MkDir xFolderPath
End If
GFilepath = ""
For Each xMailItem In xSelection
Set xAttachments = xMailItem.Attachments
xAttCount = xAttachments.Count
xSaveFiles = ""
If xAttCount > 0 Then
For i = xAttCount To 1 Step -1
GCount = 0
xFilePath = xFolderPath & xAttachments.Item(i).FileName
GFilepath = xFilePath
xFilePath = FileRename(xFilePath)
If IsEmbeddedAttachment(xAttachments.Item(i)) = False Then
xAttachments.Item(i).SaveAsFile xFilePath
If xMailItem.BodyFormat <> olFormatHTML Then
xSaveFiles = xSaveFiles & vbCrLf & "<Error! Hyperlink reference not valid.>"
Else
xSaveFiles = xSaveFiles & "<br>" & "<a href='file://" & xFilePath & "'>" & xFilePath & "</a>"
End If
End If
Next i
End If
Next
Set xAttachments = Nothing
Set xMailItem = Nothing
Set xSelection = Nothing
MsgBoX prompt:="File Transfer Complete", Title:="Sweatyjalapenos tha Goat"
End Sub

Function FileRename(FilePath As String) As String
Dim xPath As String
Dim xFso As Variant
On Error Resume Next
Set xFso = CreateObject("Scripting.FileSystemObject")
xPath = FilePath
FileRename = xPath
If xFso.FileExists(xPath) Then
GCount = GCount + 1
xPath = xFso.GetParentFolderName(GFilepath) & "\" & xFso.GetBaseName(GFilepath) & " " & GCount & "." + xFso.GetExtensionName(GFilepath)
FileRename = FileRename(xPath)
End If
xFso = Nothing
End Function

Function IsEmbeddedAttachment(Attach As Attachment)
Dim xItem As MailItem
Dim xCid As String
Dim xID As String
Dim xHtml As String
On Error Resume Next
IsEmbeddedAttachment = False
Set xItem = Attach.Parent
If xItem.BodyFormat <> olFormatHTML Then Exit Function
xCid = ""
xCid = Attach.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F")
If xCid <> "" Then
xHtml = xItem.HTMLBody
xID = "cid:" & xCid
If InStr(xHtml, xID) > 0 Then
IsEmbeddedAttachment = True

End If
End If
End Function
This comment was minimized by the moderator on the site
Very nice script as of 2022-10-19 works great, for me doesn't seem to change original message by adding text. The only thing I changed is I added message received date time to each file name with the following format so it would nicely sort by date time in Windows folder: "yyyy-mm-dd HH-mm-ss ".

Code:

Dim GCount As Integer
Dim GFilepath As String
Public Sub SaveAttachments()
'Update 20200821
Dim xMailItem As Outlook.MailItem
Dim xAttachments As Outlook.Attachments
Dim xSelection As Outlook.Selection
Dim i As Long
Dim xAttCount As Long
Dim xFilePath As String, xFolderPath As String, xSaveFiles As String, xDateFormat As String
On Error Resume Next
xFolderPath = CreateObject("WScript.Shell").SpecialFolders(16)
Set xSelection = Outlook.Application.ActiveExplorer.Selection
xFolderPath = xFolderPath & "\Attachments\"
If VBA.Dir(xFolderPath, vbDirectory) = vbNullString Then
VBA.MkDir xFolderPath
End If
GFilepath = ""
For Each xMailItem In xSelection
Set xAttachments = xMailItem.Attachments
xAttCount = xAttachments.Count
xSaveFiles = ""
If xAttCount > 0 Then
For i = xAttCount To 1 Step -1
GCount = 0
xDateFormat = Format(xMailItem.ReceivedTime, "yyyy-mm-dd HH-mm-ss ")
xFilePath = xFolderPath & xDateFormat & xAttachments.Item(i).FileName
GFilepath = xFilePath
xFilePath = FileRename(xFilePath)
If IsEmbeddedAttachment(xAttachments.Item(i)) = False Then
xAttachments.Item(i).SaveAsFile xFilePath
If xMailItem.BodyFormat <> olFormatHTML Then
xSaveFiles = xSaveFiles & vbCrLf & "<Error! Hyperlink reference not valid.>"
Else
xSaveFiles = xSaveFiles & "<br>" & "<a href='file://" & xFilePath & "'>" & xFilePath & "</a>"
End If
End If
Next i
End If
Next
Set xAttachments = Nothing
Set xMailItem = Nothing
Set xSelection = Nothing
End Sub

Function FileRename(FilePath As String) As String
Dim xPath As String
Dim xFso As FileSystemObject
On Error Resume Next
Set xFso = CreateObject("Scripting.FileSystemObject")
xPath = FilePath
FileRename = xPath
If xFso.FileExists(xPath) Then
GCount = GCount + 1
xPath = xFso.GetParentFolderName(GFilepath) & "\" & xFso.GetBaseName(GFilepath) & " " & GCount & "." + xFso.GetExtensionName(GFilepath)
FileRename = FileRename(xPath)
End If
xFso = Nothing
End Function

Function IsEmbeddedAttachment(Attach As Attachment)
Dim xItem As MailItem
Dim xCid As String
Dim xID As String
Dim xHtml As String
On Error Resume Next
IsEmbeddedAttachment = False
Set xItem = Attach.Parent
If xItem.BodyFormat <> olFormatHTML Then Exit Function
xCid = ""
xCid = Attach.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F")
If xCid <> "" Then
xHtml = xItem.HTMLBody
xID = "cid:" & xCid
If InStr(xHtml, xID) > 0 Then
IsEmbeddedAttachment = True
End If
End If
End Function
This comment was minimized by the moderator on the site
Hi Oigo,
This is a very useful VBA script. Thank you for sharing it.
This comment was minimized by the moderator on the site
Hi crystal,

sorry for not being clear.

I was trying to use the code above mentioned. However, apparently I was doing something wrong. I was thinking that I might need to amend some parts in the code shown. For instance the path where to save the attachments and maybe some other parts. Therefore I was asking if you could share the code highlighting the parts which needs tailoring and how to tailor them.

Many thanks,
BR
This comment was minimized by the moderator on the site
Hi Rokkie,
Did you get any error prompt when the code runs? Or which line in your code is highlighted? I need more details so I can see where you can modify the code.
This comment was minimized by the moderator on the site
Hey crystal,

completeley new to this VBA. Can you share a code to use which shows where I have to amend with an example? As a Rookie it is a bit difficult to figure it out.

I am working via a Ctrix connection. Could this be a blocker for the macro?

Much appreaciate the help.
This comment was minimized by the moderator on the site
Hi Rookie,
Sorry I don't understand what you mean: "Can you share a code to use which shows where I have to amend with an example?"
And the code operates on selected emails in Outlook, Ctrix Connection does not block the macro.
This comment was minimized by the moderator on the site
Hi, I am running this Code 1 to extract .txt files from separate sub-folders of an inbox. It works great out of one sub-folder but not at all out of another sub-folder. I have tried forwarding the relevant email and attachment into other inboxes but no luck. The files are automatically generated and sent to the different sub-folders and only vary by a single letter in their title

Any help much is appreciated
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations