儘管Outlook不允許直接將附件壓縮為 RAR 文件,您仍然可以使用本文介紹的VBA代碼輕鬆實現它。
眾所周知,將許多大文件附加到一封電子郵件中時,您可能會收到有關Outlook中附件大小限制的警告。 此外,如果電子郵件中包含太大的附件,則成功發送出去將變得更加困難。 因此,面對此類附件,您可以選擇將其壓縮為 RAR 文件,可以在某種程度上減小附件的大小。

通常,將文件壓縮為 RAR 文件,您只能在本地驅動器中實現它,因為Outlook不提供這種本機壓縮功能。 但是,許多人希望直接在Outlook中完成它。 因此,這裡我們將教您如何使用Outlook VBA。
快速將所有附件壓縮到 RAR Outlook電子郵件中的文件
- 首先,啟動Outlook應用程序。
- 然後在Outlook主窗口中按“ Alt + F11”鍵。
- 接下來,您將進入“ Microsoft Visual Basic for Applications”窗口。 您需要打開一個空模塊。
- 隨後,將以下VBA代碼複製並粘貼到該模塊中。
Sub RarAttachments()
Dim objMail As Outlook.MailItem
Dim objAttachments As Outlook.attachments
Dim objAttachment As Outlook.Attachment
Dim objFileSystem As Object
Dim objShell As Object
Dim strTempFolder As Variant
Dim strRARFile As Variant
Dim strSourceFile As String
'Save the attachments to Temporary folder
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
strTempFolder = objFileSystem.GetSpecialFolder(2).Path & "\Temp " & Format(Now, "YYYY-MM-DD hh-mm-ss")
MkDir (strTempFolder)
Set objMail = Outlook.Application.ActiveInspector.CurrentItem
Set objAttachments = objMail.attachments
For Each objAttachment In objAttachments
objAttachment.SaveAsFile (strTempFolder & "\" & objAttachment.FileName)
Next
'Create a new RAR file
strRARFile = InputBox("Specify a name for the new zip file", "Name Zip File", objMail.Subject)
strRARFile = objFileSystem.GetSpecialFolder(2).Path & "\" & strRARFile & ".rar"
Open strRARFile For Output As #1
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
Close #1
Set objShell = CreateObject("Shell.Application")
'Add the files to the New RAR file
strSourceFile = Dir(strTempFolder)
While strSourceFile <> ""
'Change "C:\Program Files (x86)\WinRAR\WinRAR.exe" to the location where your WinRAR is installed
objShell.Run Chr(34) & "C:\Program Files (x86)\WinRAR\WinRAR.exe" & Chr(34) & " a -r" & Chr(34) & strRARFile & Chr(34) & " " & Chr(34) & strSourceFile & Chr(34)
strSourceFile = Dir
Wend
'Delete all the attachments
Set objAttachments = objMail.attachments
While objAttachments.Count > 0
objAttachments.Item(1).Delete
Wend
'Add the new RAR file to the current email
objMail.attachments.Add strRARFile
'Prompt you
MsgBox "Complete!", vbExclamation
End Sub
- 之後,將您的Outlook宏安全級別更改為低。
- 以後,為了方便訪問,您可以將宏添加到“快速訪問工具欄”。
- 最終您可以嘗試一下。
- 首先,打開包含許多附件的電子郵件。
- 然後按快速訪問工具欄中的宏按鈕。
- 接下來,您需要輸入新名稱 RAR 文件,然後單擊“確定”。
- 之後,所有原始附件將被替換為新的附件 RAR 像截圖一樣的文件:
的unrar .RAR Outlook中的附件
同樣,Outlook 也不允許使用者直接解壓縮檔案。 .RAR 其中的文件。因此,如果您想查看內部文件, .RAR 附件,您需要將其保存並解壓縮到本地驅動器中。 但是,這無疑是乏味的。 幸運的是,您仍然可以使用VBA在Outlook中實現此功能,這在我之前的文章“如何解壓縮 .RAR 通過VBA直接在Outlook中附件“。
作者簡介:
Shirley Zhang是的數據恢復專家 DataNumen,Inc.是數據恢復技術的全球領導者,包括 SQL Server 腐敗 和Outlook修復軟件產品。 欲了解更多信息,請訪問 萬維網。datanumen.COM

