ไปยังเนื้อหาหลัก

วิธีคัดลอกโครงสร้างโฟลเดอร์ Outlook ไปยังเดสก์ท็อป (Windows Explorer)

ดังที่คุณทราบเราสามารถใช้คุณลักษณะเก็บถาวรเพื่อคัดลอกโครงสร้างโฟลเดอร์ไปยัง Outlook อื่นได้ แต่คุณรู้วิธีคัดลอกโครงสร้างโฟลเดอร์ Outlook ไปยังโฟลเดอร์หน้าต่างบางโฟลเดอร์เช่นเดสก์ท็อปหรือไม่ บทความนี้จะแนะนำ VBA เพื่อคัดลอกโครงสร้างโฟลเดอร์ Outlook ไปยัง windows explorer ได้อย่างง่ายดาย

คัดลอกโครงสร้างโฟลเดอร์ Outlook ไปยังเดสก์ท็อป (windows explorer)

Office Tab - เปิดใช้งานการแก้ไขแบบแท็บและการเรียกดูใน Microsoft Office ทำให้งานเป็นเรื่องง่าย
Kutools for Outlook - เพิ่ม Outlook ด้วยฟีเจอร์ขั้นสูงกว่า 100+ รายการเพื่อประสิทธิภาพที่เหนือกว่า
เพิ่มประสิทธิภาพ Outlook 2021 - 2010 หรือ Outlook 365 ของคุณด้วยฟีเจอร์ขั้นสูงเหล่านี้ เพลิดเพลินกับการทดลองใช้ฟรี 60 วันและยกระดับประสบการณ์อีเมลของคุณ!

คัดลอกโครงสร้างโฟลเดอร์ Outlook ไปยังเดสก์ท็อป (windows explorer)

โปรดทำตามขั้นตอนด้านล่างเพื่อคัดลอกโครงสร้างโฟลเดอร์ Outlook ไปยังเดสก์ท็อปหรือ windows explorer

1. ในบานหน้าต่างนำทางโปรดคลิกเพื่อไฮไลต์โฟลเดอร์ที่ระบุซึ่งคุณจะคัดลอกโครงสร้างโฟลเดอร์แล้วกด อื่น ๆ + F11 ปุ่มเพื่อเปิดหน้าต่าง Microsoft Visual Basic for Applications

2 คลิก เครื่องมือ > อ้างอิง เพื่อเปิดกล่องโต้ตอบการอ้างอิง จากนั้นในกล่องโต้ตอบให้ทำเครื่องหมายที่ รันไทม์การเขียนสคริปต์ของ Microsoft ตัวเลือกและคลิกที่ OK ปุ่ม. ดูภาพหน้าจอ:

3 คลิก สิ่งที่ใส่เข้าไป > โมดูลแล้วคัดลอกและวางโค้ด VBA ด้านล่างลงในหน้าต่างโมดูลใหม่

VBA: คัดลอกโครงสร้างโฟลเดอร์ Outlook ไปยัง windows explorer

Dim xFSO As Scripting.FileSystemObject
Sub CopyOutlookFldStructureToWinExplorer()
    ExportAction "Copy"
End Sub
  
Sub ExportAction(xAction As String)
Dim xFolder As Outlook.Folder
Dim xFldPath As String
xFldPath = SelectAFolder()
If xFldPath = "" Then
    MsgBox "You did not select a folder. Export cancelled.", vbInformation + vbOKOnly, "Kutools for Outlook"
Else
    Set xFSO = New Scripting.FileSystemObject
    Set xFolder = Outlook.Application.ActiveExplorer.CurrentFolder
    ExportOutlookFolder xFolder, xFldPath
End If
Set xFolder = Nothing
Set xFSO = Nothing
End Sub

Sub ExportOutlookFolder(ByVal OutlookFolder As Outlook.Folder, xFldPath As String)
Dim xSubFld As Outlook.Folder
Dim xItem As Object
Dim xPath As String
Dim xFilePath As String
Dim xSubject As String
Dim xCount As Integer
Dim xFilename As String
On Error Resume Next
xPath = xFldPath & "\" & OutlookFolder.Name
'?????????,??????
If Dir(xPath, 16) = Empty Then MkDir xPath
For Each xItem In OutlookFolder.Items
    xSubject = ReplaceInvalidCharacters(xItem.Subject)
    xFilename = xSubject & ".msg"
    xCount = 0
    xFilePath = xPath & "\" & xFilename
    If xFSO.FileExists(xFilePath) Then
        xCount = xCount + 1
        xFilename = xSubject & " (" & xCount & ").msg"
        xFilePath = xPath & "\" & xFilename
    End If
    xItem.SaveAs xFilePath, olMSG
Next
For Each xSubFld In OutlookFolder.Folders
    ExportOutlookFolder xSubFld, xPath
Next
Set OutlookFolder = Nothing
Set xItem = Nothing
End Sub

Function SelectAFolder() As String
Dim xSelFolder As Object
Dim xShell As Object
On Error Resume Next
Set xShell = CreateObject("Shell.Application")
Set xSelFolder = xShell.BrowseForFolder(0, "Select a folder", 0, 0)
If Not TypeName(xSelFolder) = "Nothing" Then
    SelectAFolder = xSelFolder.self.Path
End If
Set xSelFolder = Nothing
Set xShell = Nothing
End Function
  
Function ReplaceInvalidCharacters(Str As String) As String
Dim xRegEx
Set xRegEx = CreateObject("vbscript.regexp")
xRegEx.Global = True
xRegEx.IgnoreCase = False
xRegEx.Pattern = "\||\/|\<|\>|""|:|\*|\\|\?"
ReplaceInvalidCharacters = xRegEx.Replace(Str, "")
End Function

4 กด F5 หรือคลิกปุ่ม วิ่ง เพื่อเรียกใช้ VBA นี้

5 ในกล่องโต้ตอบเรียกดูโฟลเดอร์ที่โผล่ออกมา โปรดเลือกโฟลเดอร์ที่ระบุที่คุณจะวางโครงสร้างโฟลเดอร์ที่คัดลอกไว้และคลิกปุ่ม OK ปุ่ม. ดูภาพหน้าจอ:

ตอนนี้ไปที่โฟลเดอร์ที่ระบุ คุณจะเห็นโครงสร้างโฟลเดอร์ถูกคัดลอกไปยังฮาร์ดดิสก์ที่ระบุ ดูภาพหน้าจอ:

หมายเหตุ: รายการโฟลเดอร์ เช่น อีเมล การนัดหมาย งาน ฯลฯ จะถูกคัดลอกไปยังโฟลเดอร์ที่เกี่ยวข้องในฮาร์ดดิสก์ด้วย


บทความที่เกี่ยวข้อง


สุดยอดเครื่องมือเพิ่มผลผลิตในสำนักงาน

Kutools สำหรับ Outlook - คุณสมบัติอันทรงพลังมากกว่า 100 รายการเพื่อเติมพลังให้กับ Outlook ของคุณ

🤖 ผู้ช่วยจดหมาย AI: ส่งอีเมลระดับมืออาชีพทันทีด้วยเวทมนตร์ AI คลิกเพียงครั้งเดียวเพื่อตอบกลับอย่างชาญฉลาด น้ำเสียงที่สมบูรณ์แบบ การเรียนรู้หลายภาษา เปลี่ยนรูปแบบการส่งอีเมลอย่างง่ายดาย! ...

📧 การทำงานอัตโนมัติของอีเมล: ไม่อยู่ที่สำนักงาน (ใช้ได้กับ POP และ IMAP)  /  กำหนดการส่งอีเมล  /  Auto CC/BCC ตามกฎเมื่อส่งอีเมล  /  ส่งต่ออัตโนมัติ (กฎขั้นสูง)   /  เพิ่มคำทักทายอัตโนมัติ   /  แบ่งอีเมลผู้รับหลายรายออกเป็นข้อความส่วนตัวโดยอัตโนมัติ ...

📨 การจัดการอีเมล์: เรียกคืนอีเมลได้อย่างง่ายดาย  /  บล็อกอีเมลหลอกลวงตามหัวเรื่องและอื่นๆ  /  ลบอีเมลที่ซ้ำกัน  /  การค้นหาขั้นสูง  /  รวมโฟลเดอร์ ...

📁 ไฟล์แนบโปรบันทึกแบทช์  /  การแยกแบทช์  /  การบีบอัดแบบแบตช์  /  บันทึกอัตโนมัติ   /  ถอดอัตโนมัติ  /  บีบอัดอัตโนมัติ ...

🌟 อินเตอร์เฟซเมจิก: 😊อีโมจิที่สวยและเจ๋งยิ่งขึ้น   /  เพิ่มประสิทธิภาพการทำงาน Outlook ของคุณด้วยมุมมองแบบแท็บ  /  ลดขนาด Outlook แทนที่จะปิด ...

???? เพียงคลิกเดียวสิ่งมหัศจรรย์: ตอบกลับทั้งหมดด้วยไฟล์แนบที่เข้ามา  /   อีเมลต่อต้านฟิชชิ่ง  /  🕘 แสดงโซนเวลาของผู้ส่ง ...

👩🏼‍🤝‍👩🏻 รายชื่อและปฏิทิน: แบทช์เพิ่มผู้ติดต่อจากอีเมลที่เลือก  /  แบ่งกลุ่มผู้ติดต่อเป็นกลุ่มแต่ละกลุ่ม  /  ลบการแจ้งเตือนวันเกิด ...

เกิน คุณสมบัติ 100 รอการสำรวจของคุณ! คลิกที่นี่เพื่อค้นพบเพิ่มเติม

 

 

Comments (16)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello, that's brilliant! How can I adjust the code to only save email attachments, not the entire message? Many thanks
This comment was minimized by the moderator on the site
'This code solves the duplicate filename problemDim xFSO As Scripting.FileSystemObject
Sub CopyOutlookFldStructureToWinExplorer()
ExportAction "Copy"
End Sub

Sub ExportAction(xAction As String)
Dim xFolder As Outlook.Folder
Dim xFldPath As String
xFldPath = SelectAFolder()
If xFldPath = "" Then
MsgBox "You did not select a folder. Export cancelled.", vbInformation + vbOKOnly, "Kutools for Outlook"
Else
Set xFSO = New Scripting.FileSystemObject
Set xFolder = Outlook.Application.ActiveExplorer.CurrentFolder
ExportOutlookFolder xFolder, xFldPath
End If
Set xFolder = Nothing
Set xFSO = Nothing
End Sub

Sub ExportOutlookFolder(ByVal OutlookFolder As Outlook.Folder, xFldPath As String)
Dim xSubFld As Outlook.Folder
Dim xItem As Object
Dim xPath As String
Dim xFilePath As String
Dim xSubject As String
Dim xCount As Integer
Dim xFilename As String
On Error Resume Next
xPath = xFldPath & "\" & OutlookFolder.Name
'?????????,??????
If Dir(xPath, 16) = Empty Then MkDir xPath

xCount = 0

For Each xItem In OutlookFolder.Items
xSubject = ReplaceInvalidCharacters(xItem.Subject)
xFilename = xSubject & ".msg"
xFilePath = xPath & "\" & xFilename
If xFSO.FileExists(xFilePath) Then
xCount = xCount + 1
xFilename = xSubject & " (" & xCount & ").msg"
xFilePath = xPath & "\" & xFilename
While xFSO.FileExists(xFilePath)
xCount = xCount + 1
xFilename = xSubject & " (" & xCount & ").msg"
xFilePath = xPath & "\" & xFilename
Wend
End If
xItem.SaveAs xFilePath, olMSG
xCount = 0
Next
For Each xSubFld In OutlookFolder.Folders
ExportOutlookFolder xSubFld, xPath
Next
Set OutlookFolder = Nothing
Set xItem = Nothing
End Sub

Function SelectAFolder() As String
Dim xSelFolder As Object
Dim xShell As Object
On Error Resume Next
Set xShell = CreateObject("Shell.Application")
Set xSelFolder = xShell.BrowseForFolder(0, "Select a folder", 0, 0)
If Not TypeName(xSelFolder) = "Nothing" Then
SelectAFolder = xSelFolder.self.Path
End If
Set xSelFolder = Nothing
Set xShell = Nothing
End Function

Function ReplaceInvalidCharacters(Str As String) As String
Dim xRegEx
Set xRegEx = CreateObject("vbscript.regexp")
xRegEx.Global = True
xRegEx.IgnoreCase = False
xRegEx.Pattern = "\||\/|\<|\>|""|:|\*|\\|\?"
ReplaceInvalidCharacters = xRegEx.Replace(Str, "")
End Function
This comment was minimized by the moderator on the site
Here is how i modified the code to make it work

i will paste it in reply
This comment was minimized by the moderator on the site
Dim xFSO As Scripting.FileSystemObject
Sub CopyOutlookFldStructureToWinExplorer()
ExportAction "Copy"
msg = MsgBox("Copy of your Inbox is successful", vbOKOnly, "Done")
End Sub

Sub ExportAction(xAction As String)
Dim xFolder As Outlook.Folder
Dim xFldPath As String
xFldPath = SelectAFolder()
If xFldPath = "" Then
MsgBox "You did not select a folder. Export cancelled.", vbInformation + vbOKOnly, "Kutools for Outlook"
Else
Set xFSO = New Scripting.FileSystemObject
Set xFolder = Outlook.Application.ActiveExplorer.CurrentFolder
ExportOutlookFolder xFolder, xFldPath
End If
Set xFolder = Nothing
Set xFSO = Nothing
End Sub

Sub ExportOutlookFolder(ByVal OutlookFolder As Outlook.Folder, xFldPath As String)
Dim xSubFld As Outlook.Folder
Dim xItem As Object
Dim xPath As String
Dim xFilePath As String
Dim xSubject As String * 100

Dim xCounter As Integer
Dim xFilename As String
Dim xFileDateRec As String

On Error Resume Next
xPath = xFldPath & "\" & ReplaceInvalidCharacters(OutlookFolder.Name)

If Dir(xPath, 16) = Empty Then MkDir xPath
xCounter = 0

For Each xItem In OutlookFolder.Items
xCounter = xCounter + 1
xSubject = ReplaceInvalidCharacters(xItem.Subject)
xFileDateRec = xItem.ReceivedTime
xFilename = ReplaceInvalidCharacters(RTrim(xSubject) & xFileDateRec & " " & xCounter & ".msg")
xFilePath = xPath & "\" & xFilename
xItem.SaveAs xFilePath, olMSG
Next
For Each xSubFld In OutlookFolder.Folders
ExportOutlookFolder xSubFld, xPath
Next
Set OutlookFolder = Nothing
Set xItem = Nothing
End Sub

Function SelectAFolder() As String
Dim xSelFolder As Object
Dim xShell As Object
On Error Resume Next
Set xShell = CreateObject("Shell.Application")
Set xSelFolder = xShell.BrowseForFolder(0, "Select a folder", 0, 0)
If Not TypeName(xSelFolder) = "Nothing" Then
SelectAFolder = xSelFolder.self.Path
End If
Set xSelFolder = Nothing
Set xShell = Nothing
End Function

Function ReplaceInvalidCharacters(Str As String) As String
Dim xRegEx
Set xRegEx = CreateObject("vbscript.regexp")
xRegEx.Global = True
xRegEx.IgnoreCase = False
xRegEx.Pattern = "\||\/|\<|\>|""|:|\*|\\|\?"
ReplaceInvalidCharacters = xRegEx.Replace(Str, "_")
End Function
This comment was minimized by the moderator on the site
If I re-run this VBA every couple months, does it only copy new email or does it copy new email and create duplicates for all existing emails?
This comment was minimized by the moderator on the site
xItem.SaveAs xFilePath, olMSG
Next
For Each xSubFld In OutlookFolder.Folders
ExportOutlookFolder xSubFld, xPath
Next
Set OutlookFolder = Nothing
Set xItem = Nothing
End Sub

Function SelectAFolder() As String
Dim xSelFolder As Object
Dim xShell As Object
On Error Resume Next
Set xShell = CreateObject("Shell.Application")
Set xSelFolder = xShell.BrowseForFolder(0, "Select a folder", 0, 0)
If Not TypeName(xSelFolder) = "Nothing" Then
SelectAFolder = xSelFolder.self.Path
End If
Set xSelFolder = Nothing
Set xShell = Nothing
End Function

Function ReplaceInvalidCharacters(Str As String) As String
Dim xRegEx
Set xRegEx = CreateObject("vbscript.regexp")
xRegEx.Global = True
xRegEx.IgnoreCase = False
xRegEx.Pattern = "\||\/|\<|\>|""|:|\*|\\|\?"
ReplaceInvalidCharacters = xRegEx.Replace(Str, "_")
End Function
This comment was minimized by the moderator on the site
What is this second piece of code? Do I use the original reply code or the second reply and that?
This comment was minimized by the moderator on the site
it is all 1 code, it was too long to post in 1 piece
This comment was minimized by the moderator on the site
hello, same thing. you code works great.. the only thing is that the duplicate names, more than (1), are not exported.
Please add the option.
This comment was minimized by the moderator on the site
Yes! the same as Ammar asked, can you modify the code so it copies every item even if it has the same name!!! this would help me a lot
This comment was minimized by the moderator on the site
Hello I have one question, I used the above mentioned code, but it is missing the related conversations as it has the same subject. This is created problem as the numbers of items in outlook not matching with number of items in folder. Can you please help to edit the above code so that it also paste all the items even though it has same subject ?
This comment was minimized by the moderator on the site
Dim xFSO As Scripting.FileSystemObject
Sub CopyOutlookFldStructureToWinExplorer()
ExportAction "Copy"
End Sub

Sub ExportAction(xAction As String)
Dim xFolder As Outlook.Folder
Dim xFldPath As String
xFldPath = SelectAFolder()
If xFldPath = "" Then
MsgBox "You did not select a folder. Export cancelled.", vbInformation + vbOKOnly, "Kutools for Outlook"
Else
Set xFSO = New Scripting.FileSystemObject
Set xFolder = Outlook.Application.ActiveExplorer.CurrentFolder
ExportOutlookFolder xFolder, xFldPath
End If
Set xFolder = Nothing
Set xFSO = Nothing
End Sub

Sub ExportOutlookFolder(ByVal OutlookFolder As Outlook.Folder, xFldPath As String)
Dim xSubFld As Outlook.Folder
Dim xItem As Object
Dim xPath As String
Dim xFilePath As String
Dim xSubject As String
Dim xCount As Integer
Dim xFilename As String
On Error Resume Next
xPath = xFldPath & "\" & OutlookFolder.Name
'?????????,??????
If Dir(xPath, 16) = Empty Then MkDir xPath
xCount = 0 ' Pasted lineFor Each xItem In OutlookFolder.Items
xSubject = ReplaceInvalidCharacters(xItem.Subject)
xFilename = xSubject & ".msg"
' Deleted line xCount = 0
xFilePath = xPath & "\" & xFilename
If xFSO.FileExists(xFilePath) Then
xCount = xCount + 1
xFilename = xSubject & " (" & xCount & ").msg"
xFilePath = xPath & "\" & xFilename
Else ' New linexCount = 0 ' New line E xItem.SaveAs xFilePath, olMSG
Next
For Each xSubFld In OutlookFolder.Folders
ExportOutlookFolder xSubFld, xPath
Next
Set OutlookFolder = Nothing
Set xItem = Nothing
End Sub

Function SelectAFolder() As String
Dim xSelFolder As Object
Dim xShell As Object
On Error Resume Next
Set xShell = CreateObject("Shell.Application")
Set xSelFolder = xShell.BrowseForFolder(0, "Select a folder", 0, 0)
If Not TypeName(xSelFolder) = "Nothing" Then
SelectAFolder = xSelFolder.self.Path
End If
Set xSelFolder = Nothing
Set xShell = Nothing
End Function

Function ReplaceInvalidCharacters(Str As String) As String
Dim xRegEx
Set xRegEx = CreateObject("vbscript.regexp")
xRegEx.Global = True
xRegEx.IgnoreCase = False
xRegEx.Pattern = "\||\/|\<|\>|""|:|\*|\\|\?"
ReplaceInvalidCharacters = xRegEx.Replace(Str, "")
End Function
This comment was minimized by the moderator on the site
This is great, thank you! What would the code look like if I just want Inbox + all subfolders? (i.e., exclude deleted items?)Thank you!Morghan
This comment was minimized by the moderator on the site
It works (sort of), but (a) there were more messages exported to one folder than were in the corresponding Outlook Folder and (b) there were fewer messages exported to one folder than were in the Outlook Folder and (c) (not 100% sure) I think one message went to the wrong folder.
This comment was minimized by the moderator on the site
I have Outlook 15, and the macro won't replace the "/" where used in Outlook folder names. It just skips those folders. Is this a compatibility issue?
This comment was minimized by the moderator on the site
Bonjour,

Serait-il possible de stocker les mails dans un fichier .pst ?

D'avance merci pour vos retours.

Cordialement,

Ando Rakotomalala
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations