Bagaimana cara mengekspor email dari beberapa folder / subfolder untuk unggul di Outlook?
Saat mengekspor folder dengan panduan Impor dan Ekspor di Outlook, itu tidak mendukung file Sertakan Subfolder opsi jika Anda mengekspor folder ke file CSV. Namun, akan sangat memakan waktu dan membosankan untuk mengekspor setiap folder ke file CSV dan kemudian mengubahnya menjadi buku kerja Excel secara manual. Di sini, artikel ini akan memperkenalkan VBA untuk mengekspor banyak folder dan subfolder ke buku kerja Excel dengan mudah.
Ekspor beberapa email dari beberapa folder / subfolder ke Excel dengan VBA
- CC / BCC Otomatis dengan aturan saat mengirim email; Maju Otomatis Beberapa Email berdasarkan aturan; Balas otomatis tanpa server pertukaran, dan lebih banyak fitur otomatis ...
- Peringatan BCC - tunjukkan pesan ketika Anda mencoba membalas semua jika alamat surat Anda ada di daftar BCC; Ingatkan Saat Lampiran Hilang, dan lebih banyak fitur pengingat ...
- Balas (Semua) Dengan Semua Lampiran dalam percakapan surat; Balas Banyak Email sekaligus; Tambah Salam Otomatis saat membalas; Tambah Tanggal & Waktu secara Otomatis ke dalam subjek ...
- Alat Lampiran: Lepaskan Otomatis, Kompres Semua, Ganti Nama Semua, Simpan Semua Otomatis ... Laporan Cepat, Hitung Email Terpilih, Hapus Duplikat Email dan Kontak ...
- Lebih dari 100 fitur canggih akan memecahkan sebagian besar masalah Anda di Outlook 2021 - 2010 atau Office 365. Fitur lengkap uji coba gratis 60 hari.
Ekspor beberapa email dari beberapa folder / subfolder ke Excel dengan VBA
Ikuti langkah-langkah di bawah ini untuk mengekspor email dari beberapa folder atau subfolder ke buku kerja Excel dengan VBA di Outlook.
1. tekan lain + F11 kunci untuk membuka jendela Microsoft Visual Basic for Applications.
2. klik Menyisipkan > Modul, lalu tempelkan kode VBA di bawah ini ke jendela Modul baru.
VBA: Ekspor email dari beberapa folder dan subfolder ke Excel
Const MACRO_NAME = "Export Outlook Folders to Excel"
Sub ExportMain()
ExportToExcel "destination_folder_path\A.xlsx", "your_email_accouny\folder\subfolder_1"
ExportToExcel "destination_folder_path\B.xlsx", "your_email_accouny\folder\subfolder_2"
MsgBox "Process complete.", vbInformation + vbOKOnly, MACRO_NAME
End Sub
Sub ExportToExcel(strFilename As String, strFolderPath As String)
Dim olkMsg As Object
Dim olkFld As Object
Dim excApp As Object
Dim excWkb As Object
Dim excWks As Object
Dim intRow As Integer
Dim intVersion As Integer
If strFilename <> "" Then
If strFolderPath <> "" Then
Set olkFld = OpenOutlookFolder(strFolderPath)
If TypeName(olkFld) <> "Nothing" Then
intVersion = GetOutlookVersion()
Set excApp = CreateObject("Excel.Application")
Set excWkb = excApp.Workbooks.Add()
Set excWks = excWkb.ActiveSheet
'Write Excel Column Headers
With excWks
.Cells(1, 1) = "Subject"
.Cells(1, 2) = "Received"
.Cells(1, 3) = "Sender"
End With
intRow = 2
For Each olkMsg In olkFld.Items
'Only export messages, not receipts or appointment requests, etc.
If olkMsg.Class = olMail Then
'Add a row for each field in the message you want to export
excWks.Cells(intRow, 1) = olkMsg.Subject
excWks.Cells(intRow, 2) = olkMsg.ReceivedTime
excWks.Cells(intRow, 3) = GetSMTPAddress(olkMsg, intVersion)
intRow = intRow + 1
End If
Next
Set olkMsg = Nothing
excWkb.SaveAs strFilename
excWkb.Close
Else
MsgBox "The folder '" & strFolderPath & "' does not exist in Outlook.", vbCritical + vbOKOnly, MACRO_NAME
End If
Else
MsgBox "The folder path was empty.", vbCritical + vbOKOnly, MACRO_NAME
End If
Else
MsgBox "The filename was empty.", vbCritical + vbOKOnly, MACRO_NAME
End If
Set olkMsg = Nothing
Set olkFld = Nothing
Set excWks = Nothing
Set excWkb = Nothing
Set excApp = Nothing
End Sub
Public Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder
Dim arrFolders As Variant
Dim varFolder As Variant
Dim bolBeyondRoot As Boolean
On Error Resume Next
If strFolderPath = "" Then
Set OpenOutlookFolder = Nothing
Else
Do While Left(strFolderPath, 1) = "\"
strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
Loop
arrFolders = Split(strFolderPath, "\")
For Each varFolder In arrFolders
Select Case bolBeyondRoot
Case False
Set OpenOutlookFolder = Outlook.Session.Folders(varFolder)
bolBeyondRoot = True
Case True
Set OpenOutlookFolder = OpenOutlookFolder.Folders(varFolder)
End Select
If Err.Number <> 0 Then
Set OpenOutlookFolder = Nothing
Exit For
End If
Next
End If
On Error GoTo 0
End Function
Function GetSMTPAddress(Item As Outlook.MailItem, intOutlookVersion As Integer) As String
Dim olkSnd As Outlook.AddressEntry
Dim olkEnt As Object
On Error Resume Next
Select Case intOutlookVersion
Case Is < 14
If Item.SenderEmailType = "EX" Then
GetSMTPAddress = SMTPEX(Item)
Else
GetSMTPAddress = Item.SenderEmailAddress
End If
Case Else
Set olkSnd = Item.Sender
If olkSnd.AddressEntryUserType = olExchangeUserAddressEntry Then
Set olkEnt = olkSnd.GetExchangeUser
GetSMTPAddress = olkEnt.PrimarySmtpAddress
Else
GetSMTPAddress = Item.SenderEmailAddress
End If
End Select
On Error GoTo 0
Set olkPrp = Nothing
Set olkSnd = Nothing
Set olkEnt = Nothing
End Function
Function GetOutlookVersion() As Integer
Dim arrVer As Variant
arrVer = Split(Outlook.Version, ".")
GetOutlookVersion = arrVer(0)
End Function
Function SMTPEX(olkMsg As Outlook.MailItem) As String
Dim olkPA As Outlook.propertyAccessor
On Error Resume Next
Set olkPA = olkMsg.propertyAccessor
SMTPEX = olkPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x5D01001E")
On Error GoTo 0
Set olkPA = Nothing
End Function
3. Harap sesuaikan kode VBA di atas sesuai kebutuhan Anda.
(1) Ganti tujuan_folder_jalur dalam kode di atas dengan jalur folder folder tujuan Anda akan menyimpan buku kerja yang diekspor, seperti C: \ Users \ DT168 \ Documents \ TEST.
(2) Ganti your_email_accouny \ folder \ subfolder_1 dan your_email_accouny \ folder \ subfolder_2 di kode di atas dengan jalur folder subfolder di Outlook, seperti Kelly @extendoffice.com \ Inbox \ A serta Kelly @extendoffice.com \ Inbox \ B
4. tekan F5 atau klik Run tombol untuk menjalankan VBA ini. Dan kemudian klik OK di kotak dialog Ekspor Outlook Folder ke Excel muncul. Lihat tangkapan layar:
Dan sekarang email dari semua subfolder atau folder tertentu di kode VBA di atas diekspor dan disimpan ke dalam buku kerja Excel.
Artikel terkait
Ekspor email menurut rentang tanggal ke file Excel atau file PST di Outlook
Ekspor dan cetak daftar semua folder dan subfolder di Outlook
Kutools for Outlook - Menghadirkan 100 Fitur Canggih ke Outlook, dan Membuat Pekerjaan Lebih Mudah!
- CC / BCC Otomatis dengan aturan saat mengirim email; Maju Otomatis Beberapa Email secara khusus; Balas otomatis tanpa server pertukaran, dan lebih banyak fitur otomatis ...
- Peringatan BCC - tunjukkan pesan ketika Anda mencoba membalas semua jika alamat email Anda ada di daftar BCC; Ingatkan Saat Lampiran Hilang, dan lebih banyak fitur pengingat ...
- Balas (Semua) Dengan Semua Lampiran di percakapan surat; Balas Banyak Email dalam hitungan detik; Tambah Salam Otomatis saat membalas; Tambahkan Tanggal ke dalam subjek ...
- Alat Lampiran: Kelola Semua Lampiran di Semua Email, Lepaskan Otomatis, Kompres Semua, Ganti Nama Semua, Simpan Semua ... Laporan Cepat, Hitung Email yang Dipilih...
- Email Sampah yang Kuat dengan kebiasaan; Hapus Duplikat Email dan Kontak... Memungkinkan Anda melakukan lebih cerdas, lebih cepat, dan lebih baik di Outlook.











