複数のフォルダー/サブフォルダーから電子メールをエクスポートしてOutlookで優れたものにする方法は?
Outlookのインポートおよびエクスポートウィザードを使用してフォルダーをエクスポートする場合、フォルダーはサポートされていません。 サブフォルダーを含める フォルダをCSVファイルにエクスポートする場合のオプション。 ただし、各フォルダをCSVファイルにエクスポートしてから手動でExcelブックに変換するのは、非常に時間と手間がかかります。 ここでは、複数のフォルダーとサブフォルダーをExcelブックに簡単にすばやくエクスポートするためのVBAを紹介します。
VBAを使用して複数のフォルダー/サブフォルダーからExcelに複数の電子メールをエクスポートする
- 自動CC / BCC メール送信時のルールによる。 自動転送 ルールによる複数の電子メール。 自動返信 Exchangeサーバーなし、およびより多くの自動機能...
- BCC警告 -メールアドレスがBCCリストにある場合、すべてに返信しようとするとメッセージを表示します。 添付ファイルがない場合に通知する、その他の機能を思い出させる...
- すべての添付ファイルで(すべて)返信 メールでの会話。 一度に多くのメールに返信します。 あいさつを自動追加 返信するとき; 件名に日付と時刻を自動追加...
- アタッチメントツール:自動デタッチ、すべて圧縮、すべての名前変更、すべて自動保存... クイックレポート、選択したメールを数える、 重複するメールと連絡先を削除する...
- 100 以上の高度な機能が あなたの問題のほとんどを解決します Outlook 2021 - 2010 または Office 365。フル機能の 60 日間無料試用版。
VBAを使用して複数のフォルダー/サブフォルダーからExcelに複数の電子メールをエクスポートする
OutlookでVBAを使用して複数のフォルダーまたはサブフォルダーからExcelブックに電子メールをエクスポートするには、以下の手順に従ってください。
1。 押す 他の + F11 キーを押して、Microsoft Visual Basic forApplicationsウィンドウを開きます。
2。 クリック インセット > モジュール、次にVBAコードの下を新しいモジュールウィンドウに貼り付けます。
VBA:複数のフォルダーとサブフォルダーから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.必要に応じて上記のVBAコードを調整してください。
(1)交換 宛先フォルダーのパス 上記のコードで、宛先フォルダーのフォルダーパスを使用して、エクスポートされたワークブックを保存します。 C:\ Users \ DT168 \ Documents \ TEST.
(2)上記のコードのyour_email_accouny \ folder \ subfolder_1とyour_email_accouny \ folder \ subfolder_2を、Outlookのサブフォルダーのフォルダーパス(次のような)に置き換えます。 ケリー@extendoffice.com \ Inbox \ A 及び ケリー@extendoffice.com \ Inbox \ B
4。 プレス F5 キーを押すか、 ラン このVBAを実行するためのボタン。 そして、 OK [OutlookフォルダをExcelにエクスポート]ダイアログボックスのボタンをクリックします。 スクリーンショットを参照してください:
そして、上記のVBAコードで指定されたすべてのサブフォルダーまたはフォルダーからの電子メールがエクスポートされ、Excelワークブックに保存されるようになりました。
関連記事
Kutools for Outlook-100の高度な機能をOutlookにもたらし、作業をはるかに簡単にします!
- 自動CC / BCC メール送信時のルールによる。 自動転送 カスタムによる複数の電子メール。 自動返信 Exchangeサーバーなし、およびより多くの自動機能...
- BCC警告 -全員に返信しようとするとメッセージを表示する メールアドレスがBCCリストにある場合; 添付ファイルがない場合に通知する、その他の機能を思い出させる...
- メール会話のすべての添付ファイルで(すべて)返信; 多くのメールに返信する すぐに; あいさつを自動追加 返信するとき; 件名に日付を追加...
- 添付ファイルツール:すべてのメールのすべての添付ファイルを管理し、 自動デタッチ, すべて圧縮、すべての名前を変更、すべて保存...クイックレポート、 選択したメールを数える...
- 強力な迷惑メール 習慣による; 重複するメールと連絡先を削除する... Outlookでよりスマートに、より速く、より良くすることができます。











