Note: The other languages of the website are Google-translated. Back to English
English English

Como salvar automaticamente e-mails do Outlook no disco rígido / disco?

Para backup, evidências de trabalho ou outros propósitos, você pode querer salvar e-mails do Outlook no disco rígido. É fácil salvar vários e-mails no disco arrastando manualmente do Outlook para o disco. No entanto, você sabe como salvar automaticamente cada e-mail recebido no disco? Este artigo apresentará um VBA para lidar com isso no Outlook.

Salve e-mails do Outlook automaticamente no disco rígido / disco

Salve e-mails do Outlook automaticamente no disco rígido / disco

Este método introduzirá um VBA para salvar automaticamente todos os e-mails recebidos no Outlook como um arquivo HTML individual no disco específico. Faça o seguinte:

1. pressione outro + F11 para abrir a janela Microsoft Visual Basic for Applications.

2. Expanda o Projeto1 e clique duas vezes Esta sessão do Outlook para abri-lo e, em seguida, cole o código VBA abaixo na janela ThisOutlookSession. Veja a imagem:

VBA: salvar automaticamente e-mails do Outlook como arquivos HTML no disco

Private WithEvents InboxItems As Outlook.Items
Sub Application_Startup()
Dim xNameSpace As Outlook.NameSpace
Set xNameSpace = Outlook.Application.Session
Set InboxItems = xNameSpace.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub InboxItems_ItemAdd(ByVal objItem As Object)
Dim xMailItem As Outlook.MailItem
Dim xFilePath As String
Dim xRegEx
Dim xFileName As String
On Error Resume Next
xFilePath = CreateObject("WScript.Shell").SpecialFolders(16)
xFilePath = xFilePath & "\MyEmails"
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FolderExists(xFilePath) = False Then
FSO.CreateFolder (xFilePath)
End If
Set xRegEx = CreateObject("vbscript.regexp")
xRegEx.Global = True
xRegEx.IgnoreCase = False
xRegEx.Pattern = "\||\/|\<|\>|""|:|\*|\\|\?"
If objItem.Class = olMail Then
Set xMailItem = objItem
xFileName = xRegEx.Replace(xMailItem.Subject, "")
xMailItem.SaveAs xFilePath & "\" & xFileName & ".html", olHTML
End If
Exit Sub
End Sub

3. Save the VBA code, and restart your Microsoft Outlook.

From now on, each incoming email will be saved as individual HTML file into the “MyEmails” folder.

(1) This VBA will create a folder named “MyEmails” under the Documents folder. You can find out the automatically saved emails with this folder path: C:\Users\your_user_name\Documents\MyEmails
(2) This VBA will works with emails received in the Inbox folder of default email account.

Related Articles

Kutools for Outlook - Brings 100 Advanced Features to Outlook, and Make Work Much Easier!

  • Auto CC/BCC by rules when sending email; Auto Forward Multiple Emails by custom; Auto Reply without exchange server, and more automatic features...
  • BCC Warning - show message when you try to reply all if your mail address is in the BCC list; Remind When Missing Attachments, and more remind features...
  • Reply (All) With All Attachments in the mail conversation; Reply Many Emails in seconds; Auto Add Greeting when reply; Add Date into subject...
  • Attachment Tools: Manage All Attachments in All Mails, Auto Detach, Compress All, Rename All, Save All... Quick Report, Count Selected Mails...
  • Powerful Junk Emails by custom; Remove Duplicate Mails and Contacts... Enable you to do smarter, faster and better in Outlook.
shot kutools outlook kutools tab 1180x121
shot kutools outlook kutools plus tab 1180x121
Comments (6)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Buonasera, è possibile modificare questo script con una versione che prevede di spostare i messaggi che arrivano in altra cartella anzichè quella classica della posta in arrivo? In altri termini, vorrei salvare automaticamente le mail che arrivano per esempio in Posta in Arrivo\Cliente1
grazie per la collaborazione
This comment was minimized by the moderator on the site
How can I add the sender's email address to the file name?
This comment was minimized by the moderator on the site
Dzień doby, robię wszystko tak jak opisane powyżej, mimo to makro nie chce działać. Czy muszę włączyć jakieś opcję albo zmienić coś w kodzie?
Nie wywala błędu jednak nie tworzy się folder a plik się nie zapisuje.

Będę bardzo wdzięczna za odpowiedź

Pozdrawiam serdecznie
This comment was minimized by the moderator on the site
Could you advise how to change this to another folder, not the Inbox?
This comment was minimized by the moderator on the site
Can i have a certain report that is emailed to me each week save to a place on my hard drive? Just this one email. Comes from same email address and has the same title each week.
This comment was minimized by the moderator on the site
I need to change the folder for one i created (no need folder inbox), and i need to change the folder to store the msg files, in my case in drive e:., thank!!!
There are no comments posted here yet
Leave your comments
Posting as Guest
Rate this post:
0   Characters
Suggested Locations