Salt la conținutul principal

Cum se salvează toate atașamentele de la mai multe e-mailuri în dosar în Outlook?

Este ușor să salvați toate atașamentele dintr-un e-mail cu funcția integrată Salvați toate atașamentele din Outlook. Cu toate acestea, dacă doriți să salvați toate atașamentele din mai multe e-mailuri simultan, nu există nicio funcție directă care vă poate ajuta. Trebuie să aplicați în mod repetat caracteristica Salvați toate atașamentele în fiecare e-mail până când toate atașamentele sunt salvate din aceste e-mailuri. Asta consumă mult timp. În acest articol, vă introducem două metode pentru a salva în bloc toate atașamentele de la mai multe e-mailuri într-un folder specific cu ușurință în Outlook.

Salvați toate atașamentele din mai multe e-mailuri în folderul cu cod VBA
Mai multe clicuri pentru a salva toate atașamentele din mai multe e-mailuri în dosar cu un instrument uimitor


Salvați toate atașamentele din mai multe e-mailuri în folderul cu cod VBA

Această secțiune prezintă un cod VBA într-un ghid pas cu pas pentru a vă ajuta să salvați rapid toate atașamentele de la mai multe e-mailuri într-un folder specific simultan. Vă rugăm să faceți următoarele.

1. În primul rând, trebuie să creați un folder pentru salvarea atașamentelor în computer.

Intră în Documente folder și creați un folder numit „Atașamente”. Vedeți captura de ecran:

2. Selectați e-mailurile pe care le veți salva atașamentele, apoi apăsați Alt + F11 tastele pentru a deschide Microsoft Visual Basic pentru aplicații fereastră.

3. clic Insera > Module pentru a deschide Module fereastră, apoi copiați unul din următorul cod VBA în fereastră.

Cod VBA 1: Salvați atașamente în bloc din mai multe e-mailuri (salvați direct atașamente cu același nume)

sfaturi: Acest cod va salva atașamente cu același nume, adăugând cifrele 1, 2, 3 ... după numele fișierelor.

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
Cod VBA 2: Salvați în bloc atașamente din mai multe e-mailuri (verificați dacă există duplicate)
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

notițe:

1) Dacă doriți să salvați toate atașamentele cu același nume într-un folder, vă rugăm să aplicați cele de mai sus Cod VBA 1. Înainte de a rula acest cod, faceți clic pe Instrumente > Referinte, și apoi verificați Runtime Microsoft Scripting cutie în Referințe - Proiect căsuță de dialog;

doc salvează atașamentele07

2) Dacă doriți să verificați numele atașamentelor duplicate, vă rugăm să aplicați codul VBA 2. După rularea codului, va apărea un dialog care să vă reamintească dacă înlocuiți atașamentele duplicate, alegeți Da or Nu în funcție de nevoile dumneavoastră.

5. apasă pe F5 tasta pentru a rula codul.

Apoi, toate atașamentele din e-mailurile selectate sunt salvate în folderul creat la pasul 1. 

note: Poate exista Microsoft Outlook caseta de prompt apare, vă rugăm să faceți clic pe Permite pentru a merge mai departe.


Salvați toate atașamentele din mai multe e-mailuri în dosar cu un instrument uimitor

Dacă sunteți un începător în VBA, aici vă recomandăm cu tărie Salvați toate atașamentele utilitatea Kutools pentru Outook Pentru dumneavoastră. Cu acest utilitar, puteți salva rapid toate atașamentele din mai multe e-mailuri simultan cu mai multe clicuri numai în Outlook.
Înainte de a aplica funcția, vă rugăm descărcați și instalați mai întâi Kutools pentru Outlook.

1. Selectați e-mailurile care conțin atașamentele pe care doriți să le salvați.

Sfat: Puteți selecta mai multe e-mailuri neadiacente apăsând pe Ctrl tasta și selectați-le unul câte unul;
Sau selectați mai multe e-mailuri adiacente ținând apăsat butonul Schimba tasta și selectați primul e-mail și ultimul.

2. clic Kutools >Instrumente de atașareSalvează tot. Vedeți captura de ecran:

3. În Salvează Setările , faceți clic pe pentru a selecta un folder pentru a salva atașamentele, apoi faceți clic pe OK butonul.

3. clic OK de două ori în următoarea fereastră care apare în caseta de dialog, Apoi toate atașamentele din e-mailurile selectate sunt salvate simultan în folderul specificat.

note:

  • 1. Dacă doriți să salvați atașamente în diferite foldere pe baza e-mailurilor, vă rugăm să verificați Creați subfoldere în stilul următor și alegeți un stil de folder din meniul derulant.
  • 2. Pe lângă salvarea tuturor atașamentelor, puteți salva atașamentele în anumite condiții. De exemplu, doriți doar să salvați fișierele atașate pdf în care numele fișierului conține cuvântul „Factură”, faceți clic pe Opţiuni avansate pentru a extinde condițiile, apoi configurați-l după cum se arată în imaginea de mai jos.
  • 3. Dacă doriți să salvați automat atașamente la sosirea e-mailului, fișierul Salvați automat atașamentele caracteristica poate ajuta.
  • 4. Pentru detașarea atașamentelor direct din e-mailurile selectate, fișierul Desprindeți toate atașamentele caracteristică a Kutools pentru Outlook vă poate face o favoare.

  Dacă doriți să aveți o perioadă de încercare gratuită (60 de zile) a acestui utilitar, vă rugăm să faceți clic pentru a-l descărca, și apoi mergeți pentru a aplica operația conform pașilor de mai sus.


Articole pe aceeași temă

Introduceți atașamente în corpul mesajului de e-mail în Outlook
În mod normal, atașamentele sunt afișate în câmpul atașat într-un e-mail de compunere. Aici acest tutorial oferă metode pentru a vă ajuta să inserați cu ușurință atașamente în corpul e-mailului în Outlook.

Descărcați / salvați automat atașamente din Outlook într-un anumit folder
În general, puteți salva toate atașamentele unui e-mail făcând clic pe Atașamente> Salvați toate atașamentele în Outlook. Dar, dacă trebuie să salvați toate atașamentele din toate e-mailurile primite și primirea e-mailurilor, vreun ideal? Acest articol va introduce două soluții pentru a descărca automat atașamente din Outlook într-un anumit folder.

Imprimați toate atașamentele în unul / mai multe e-mailuri în Outlook
După cum știți, va imprima conținutul e-mailului, cum ar fi antetul, corpul, doar când faceți clic pe Fișier> Tipărire în Microsoft Outlook, dar nu va imprima atașamentele. Aici vă vom arăta cum să imprimați ușor toate atașamentele într-un e-mail selectat în Microsoft Outlook.

Căutați cuvinte în atașament (conținut) în Outlook
Când tastați un cuvânt cheie în caseta Căutare instantanee din Outlook, acesta va căuta cuvântul cheie în subiectele, corpurile, atașamentele e-mailurilor etc. Dar acum trebuie doar să caut cuvântul cheie în conținutul atașamentului numai în Outlook, vreo idee? Acest articol vă arată pașii detaliați pentru a căuta cu ușurință cuvintele din conținutul atașamentului în Outlook.

Păstrați atașamentele atunci când răspundeți în Outlook
Când redirecționăm un mesaj de e-mail în Microsoft Outlook, atașamentele originale din acest mesaj de e-mail rămân în mesajul redirecționat. Cu toate acestea, atunci când răspundem la un mesaj de e-mail, atașamentele originale nu vor fi atașate în noul mesaj de răspuns. Aici vom introduce câteva trucuri despre păstrarea atașamentelor originale atunci când răspundem în Microsoft Outlook.


Cele mai bune instrumente de productivitate de birou

Kutools pentru Outlook - Peste 100 de funcții puternice pentru a vă supraalimenta Outlook

🤖 AI Mail Assistant: E-mailuri profesionale instantanee cu magie AI--un singur clic pentru răspunsuri geniale, ton perfect, stăpânire în mai multe limbi. Transformați e-mailurile fără efort! ...

📧 Automatizare e-mail: În afara biroului (disponibil pentru POP și IMAP)  /  Programați trimiterea de e-mailuri  /  CC/BCC automat după reguli la trimiterea e-mailului  /  Redirecționare automată (Reguli avansate)   /  Adăugare automată felicitare   /  Împărțiți automat e-mailurile cu mai mulți destinatari în mesaje individuale ...

📨 Managementul e-mail: Amintește-ți cu ușurință e-mailurile  /  Blocați e-mailurile înșelătorii de către subiecți și alții  /  Ștergeți e-mailurile duplicate  /  Cautare Avansata  /  Consolidați foldere ...

📁 Atașamente ProSalvați în serie  /  Detașare lot  /  Compresă în loturi  /  Salvare automata   /  Detașare automată  /  Comprimare automată ...

🌟 Magia interfeței: 😊Mai multe emoji drăguțe și cool   /  Îmbunătățiți-vă productivitatea Outlook cu vizualizările cu file  /  Minimizați Outlook în loc să închideți ...

???? Minuni cu un singur clic: Răspundeți tuturor cu atașamentele primite  /   E-mailuri anti-phishing  /  🕘Afișați fusul orar al expeditorului ...

👩🏼‍🤝‍👩🏻 Contacte și calendar: Adăugați în lot contacte din e-mailurile selectate  /  Împărțiți un grup de contact în grupuri individuale  /  Eliminați mementouri de ziua de naștere ...

Peste 100 Caracteristici Așteaptă explorarea ta! Click aici pentru a descoperi mai multe.

 

 

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