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

จะย้ายไฟล์เฉพาะจากโฟลเดอร์หนึ่งไปยังอีกโฟลเดอร์หนึ่งใน Excel ได้อย่างไร?

สมมติว่าฉันมีโฟลเดอร์ขนาดใหญ่ซึ่งมีไฟล์หลายประเภทเช่น docx, jpg, xlsx เป็นต้นตามภาพหน้าจอต่อไปนี้ ตอนนี้ฉันต้องการย้ายไฟล์บางประเภทจากโฟลเดอร์ไปยังโฟลเดอร์ใหม่โดยไม่ต้องย้ายทีละไฟล์ด้วยตนเอง คุณมีความคิดที่ดีในการแก้ปัญหานี้ใน Excel หรือไม่?

ย้ายไฟล์เฉพาะจากโฟลเดอร์หนึ่งไปยังโฟลเดอร์อื่นด้วยรหัส VBA


ย้ายไฟล์เฉพาะจากโฟลเดอร์หนึ่งไปยังโฟลเดอร์อื่นด้วยรหัส VBA

หากต้องการย้ายไฟล์บางประเภทจากโฟลเดอร์หนึ่งไปยังอีกโฟลเดอร์หนึ่งโดยเร็วที่สุดเท่าที่คุณต้องการรหัส VBA ต่อไปนี้อาจช่วยคุณได้โปรดดำเนินการดังนี้:

1. กดค้างไว้ ALT + F11 คีย์เพื่อเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

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

รหัส VBA: ย้ายไฟล์บางประเภทจากโฟลเดอร์หนึ่งไปยังอีกโฟลเดอร์หนึ่ง:

Sub MoveFiles()
'Updateby Extendoffice
    Dim xFd As FileDialog
    Dim xTFile As String
    Dim xExtArr As Variant
    Dim xExt As Variant
    Dim xSPath As String
    Dim xDPath As String
    Dim xSFile As String
    Dim xCount As Long
    Set xFd = Application.FileDialog(msoFileDialogFolderPicker)
    xFd.Title = "Please select the original folder:"
    If xFd.Show = -1 Then
        xSPath = xFd.SelectedItems(1)
    Else
        Exit Sub
    End If
    If Right(xSPath, 1) <> "\" Then xSPath = xSPath + "\"
    xFd.Title = "Please select the destination folder:"
    If xFd.Show = -1 Then
        xDPath = xFd.SelectedItems(1)
    Else
        Exit Sub
    End If
    If Right(xDPath, 1) <> "\" Then xDPath = xDPath + "\"
    xExtArr = Array("*.xlsx*", "*.jpg")
    For Each xExt In xExtArr
        xTFile = Dir(xSPath & xExt)
        Do While xTFile <> ""
            xSFile = xSPath & xTFile
            FileCopy xSFile, xDPath & xTFile
            Kill xSFile
            xTFile = Dir
            xCount = xCount + 1
        Loop
    Next
    MsgBox "Total number of moved files is: " & xCount, vbInformation, "Kutools for Excel"
End Sub

หมายเหตุ: ในโค้ดด้านบน "* .xlsx *""* .jpg"ในสคริปต์: xExtArr = อาร์เรย์ ("*. xlsx *", "* .jpg") เป็นประเภทไฟล์ที่คุณต้องการย้ายคุณสามารถเปลี่ยนเป็นประเภทอื่นหรือเพิ่มประเภทไฟล์อื่น ๆ ได้ตามต้องการ

3. จากนั้นกด F5 คีย์เพื่อเรียกใช้รหัสนี้และหน้าต่างจะโผล่ขึ้นมาเพื่อเตือนให้คุณเลือกโฟลเดอร์เดิมที่คุณต้องการย้ายไฟล์ดูภาพหน้าจอ:

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

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

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

🤖 Kutools AI ผู้ช่วย: ปฏิวัติการวิเคราะห์ข้อมูลโดยยึดตาม: การดำเนินการที่ชาญฉลาด   |  สร้างรหัส  |  สร้างสูตรที่กำหนดเอง  |  วิเคราะห์ข้อมูลและสร้างแผนภูมิ  |  เรียกใช้ฟังก์ชัน Kutools...
คุณสมบัติยอดนิยม: ค้นหา เน้น หรือระบุรายการที่ซ้ำกัน   |  ลบแถวว่าง   |  รวมคอลัมน์หรือเซลล์โดยไม่สูญเสียข้อมูล   |   รอบโดยไม่มีสูตร ...
การค้นหาขั้นสูง: VLookup หลายเกณฑ์    VLookup หลายค่า  |   VLookup ข้ามหลายแผ่น   |   การค้นหาที่ไม่ชัดเจน ....
รายการแบบเลื่อนลงขั้นสูง: สร้างรายการแบบหล่นลงอย่างรวดเร็ว   |  รายการแบบหล่นลงขึ้นอยู่กับ   |  เลือกหลายรายการแบบหล่นลง ....
ผู้จัดการคอลัมน์: เพิ่มจำนวนคอลัมน์เฉพาะ  |  ย้ายคอลัมน์  |  สลับสถานะการมองเห็นของคอลัมน์ที่ซ่อนอยู่  |  เปรียบเทียบช่วงและคอลัมน์ ...
คุณสมบัติเด่น: กริดโฟกัส   |  มุมมองการออกแบบ   |   บาร์สูตรใหญ่    สมุดงานและตัวจัดการชีต   |  ห้องสมุดทรัพยากร (ข้อความอัตโนมัติ)   |  เลือกวันที่   |  รวมแผ่นงาน   |  เข้ารหัส/ถอดรหัสเซลล์    ส่งอีเมลตามรายการ   |  ซุปเปอร์ฟิลเตอร์   |   ตัวกรองพิเศษ (กรองตัวหนา/ตัวเอียง/ขีดทับ...) ...
ชุดเครื่องมือ 15 อันดับแรก12 ข้อความ เครื่องมือ (เพิ่มข้อความ, ลบอักขระ, ... )   |   50 + แผนภูมิ ประเภท (แผนภูมิ Gantt, ... )   |   40+ ใช้งานได้จริง สูตร (คำนวณอายุตามวันเกิด, ... )   |   19 การแทรก เครื่องมือ (ใส่ QR Code, แทรกรูปภาพจากเส้นทาง, ... )   |   12 การแปลง เครื่องมือ (ตัวเลขเป็นคำ, การแปลงสกุลเงิน, ... )   |   7 ผสานและแยก เครื่องมือ (แถวรวมขั้นสูง, แยกเซลล์, ... )   |   ... และอื่น ๆ

เพิ่มพูนทักษะ Excel ของคุณด้วย Kutools สำหรับ Excel และสัมผัสประสิทธิภาพอย่างที่ไม่เคยมีมาก่อน Kutools สำหรับ Excel เสนอคุณสมบัติขั้นสูงมากกว่า 300 รายการเพื่อเพิ่มประสิทธิภาพและประหยัดเวลา  คลิกที่นี่เพื่อรับคุณสมบัติที่คุณต้องการมากที่สุด...

รายละเอียด


แท็บ Office นำอินเทอร์เฟซแบบแท็บมาที่ Office และทำให้งานของคุณง่ายขึ้นมาก

  • เปิดใช้งานการแก้ไขและอ่านแบบแท็บใน Word, Excel, PowerPoint, ผู้จัดพิมพ์, Access, Visio และโครงการ
  • เปิดและสร้างเอกสารหลายรายการในแท็บใหม่ของหน้าต่างเดียวกันแทนที่จะเป็นในหน้าต่างใหม่
  • เพิ่มประสิทธิภาพการทำงานของคุณ 50% และลดการคลิกเมาส์หลายร้อยครั้งให้คุณทุกวัน!
Comments (10)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
i get no popups after theselection screen
This comment was minimized by the moderator on the site
Hi,
Code works great for what I am doing. Thank you! How do you have it check if files exist in the destination folder and prompt the user to ask if they want to overwrite the files or save as another file name? I am working with .pdf files saving to the destination folder.
This comment was minimized by the moderator on the site
To move or copy files from a folder to another based on excel list, and destination (path)
on excel list. plz help...
This comment was minimized by the moderator on the site
Hello
To move or copy files from a folder to another based on excel list, the following article may help you!
This comment was minimized by the moderator on the site
Hi,
I need a help. Can we select few files and move them in to a separate folder by list in excel file?
thanks in advance
This comment was minimized by the moderator on the site
thanks a lot for your big help
This comment was minimized by the moderator on the site
Hello, Kumar,
To move or copy files from a folder to another based on excel list, the following article may help you!
https://www.extendoffice.com/documents/excel/4775-move-files-based-on-excel-list.html

Hope it can help you, thank you!
This comment was minimized by the moderator on the site
Can we select destinaton path in excel list on this macro. plz help.
This comment was minimized by the moderator on the site
Thank you very much, this is excellent. Really appreciate your help.
This comment was minimized by the moderator on the site
Hi

Thanks for helpful tip. I have around 5000 files listed on one excel file. I need to search all these files from the entire computer , if file names are matched then copy and paste in another folder
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations