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
- Otomatiskan pengiriman email dengan CC / BCC Otomatis, Maju Otomatis berdasarkan aturan; mengirim Balas otomatis (Di Luar Kantor) tanpa memerlukan server pertukaran...
- Dapatkan pengingat seperti Peringatan BCC saat membalas semua saat Anda berada di daftar BCC, dan Ingatkan Saat Lampiran Hilang untuk lampiran yang terlupakan...
- Tingkatkan efisiensi email dengan Balas (Semua) Dengan Lampiran, Tambahkan Ucapan atau Tanggal & Waktu secara Otomatis ke Tanda Tangan atau Subjek, Balas Beberapa Email...
- Sederhanakan pengiriman email dengan Ingat Email, Alat Lampiran (Kompres Semua, Simpan Otomatis Semua...), Hapus Duplikat, dan Laporan Cepat...
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 \Kotak Masuk\A dan \Kotak Masuk\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
Alat Produktivitas Kantor Terbaik
Kutools untuk Outlook - Lebih dari 100 Fitur Canggih untuk Meningkatkan Outlook Anda
🤖 Asisten Surat AI: Email profesional instan dengan keajaiban AI--satu klik untuk mendapatkan balasan jenius, nada sempurna, penguasaan multibahasa. Ubah email dengan mudah! ...
📧 Email Otomatis: Di Luar Kantor (Tersedia untuk POP dan IMAP) / Jadwal Kirim Email / Auto CC/BCC Sesuai Aturan Saat Mengirim Email / Penerusan Otomatis (Aturan Lanjutan) / Tambah Salam Otomatis / Secara Otomatis Membagi Email Multi-Penerima menjadi Pesan Individual ...
📨 email Management: Mengingat Email dengan Mudah / Blokir Email Penipuan berdasarkan Subjek dan Lainnya / Hapus Email Duplikat / Pencarian / Konsolidasi Folder ...
📁 Lampiran Pro: Penyimpanan Batch / Pelepasan Batch / Kompres Batch / Penyimpanan otomatis / Lepaskan Otomatis / Kompres Otomatis ...
🌟 Antarmuka Ajaib: 😊Lebih Banyak Emoji Cantik dan Keren / Tingkatkan Produktivitas Outlook Anda dengan Tampilan Tab / Minimalkan Outlook Daripada Menutup ...
👍 Keajaiban sekali klik: Balas Semua dengan Lampiran Masuk / Email Anti-Phishing / 🕘Tampilkan Zona Waktu Pengirim ...
👩🏼🤝👩🏻 Kontak & Kalender: Batch Tambahkan Kontak Dari Email yang Dipilih / Bagi Grup Kontak menjadi Grup Individual / Hapus Pengingat Ulang Tahun ...
Lebih 100 Fitur Tunggu Eksplorasi Anda! Klik Di Sini untuk Menemukan Lebih Banyak.