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

วิธีการนำเข้าไฟล์ csv / text / xml หลายชุดใน Excel อย่างรวดเร็ว

ใน Excel คุณอาจเชื่อมโยงกับการบันทึกสมุดงานเป็นไฟล์ csv ไฟล์ข้อความหรือไฟล์ xml แต่คุณเคยพยายามนำเข้าไฟล์ csv / text / xml หลายไฟล์จากโฟลเดอร์ลงในสมุดงานหรือแผ่นงานหรือไม่? ในบทความนี้ฉันแนะนำวิธีการบางอย่างเพื่อนำเข้าแบทช์อย่างรวดเร็ว

นำเข้าไฟล์ข้อความหลายไฟล์จากโฟลเดอร์ไปยังแต่ละแผ่นงานของสมุดงานด้วย VBA

นำเข้าไฟล์ csv หลายไฟล์จากโฟลเดอร์ลงในแผ่นงานเดียวด้วย VBA

นำเข้าไฟล์ xml หลายไฟล์จากโฟลเดอร์ลงในแผ่นงานเดียวด้วย VBA

นำเข้าหรือรวมไฟล์ xml / csv หลายไฟล์ลงในแผ่นงานหรือสมุดงานด้วย Kutools for Excel ความคิดที่ดี 3

ส่งออกแต่ละแผ่นเป็น csv / text / pdf ไปยังโฟลเดอร์ด้วย Kutools for Excelความคิดที่ดี 3


ในการนำเข้าไฟล์ข้อความจากโฟลเดอร์ไปยังสมุดงานคุณสามารถใช้ VBA ด้านล่างเพื่อจัดการได้อย่างรวดเร็ว

1. เปิดใช้งานสมุดงานเปล่าแล้วกด Alt + F11 กุญแจเพื่อเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

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

VBA: นำเข้าไฟล์ข้อความทั้งหมดจากโฟลเดอร์ลงในสมุดงาน

Sub LoadPipeDelimitedFiles()
'UpdatebyKutoolsforExcel20151214
    Dim xStrPath As String
    Dim xFileDialog As FileDialog
    Dim xFile As String
    Dim xCount As Long
    On Error GoTo ErrHandler
    Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
    xFileDialog.AllowMultiSelect = False
    xFileDialog.Title = "Select a folder [Kutools for Excel]"
    If xFileDialog.Show = -1 Then
        xStrPath = xFileDialog.SelectedItems(1)
    End If
    If xStrPath = "" Then Exit Sub
    Application.ScreenUpdating = False
    xFile = Dir(xStrPath & "\*.txt")
    Do While xFile <> ""
        xCount = xCount + 1
        Sheets(xCount).Select
        With ActiveSheet.QueryTables.Add(Connection:="TEXT;" _
          & xStrPath & "\" & xFile, Destination:=Range("A1"))
            .Name = "a" & xCount
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = 437
            .TextFileStartRow = 1
            .TextFileParseType = xlDelimited
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = False
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = False
            .TextFileSpaceDelimiter = False
            .TextFileOtherDelimiter = "|"
            .TextFileColumnDataTypes = Array(1, 1, 1)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
            xFile = Dir
        End With
    Loop
    Application.ScreenUpdating = True
    Exit Sub
ErrHandler:
    MsgBox "no files txt", , "Kutools for Excel"
End Sub

3 กด F5 คีย์หรือ วิ่ง เพื่อเรียกใช้ VBA และเลือกโฟลเดอร์ที่คุณต้องการนำเข้าไฟล์ข้อความจากในกล่องโต้ตอบ popping ดูภาพหน้าจอ:

doc นำเข้าข้อความ csv หลาย xml 1

4. แล้วคลิก OKและไฟล์ข้อความแต่ละไฟล์ในโฟลเดอร์ที่เลือกจะถูกนำเข้าในแผ่นงานเดียวของสมุดงานที่ใช้งานอยู่ ดูภาพหน้าจอ:

doc นำเข้าข้อความ csv หลาย xml 2doc นำเข้าข้อความ csv หลาย xml 3

รวมหลายแผ่นงาน / สมุดงานเป็นแผ่นงานเดียวหรือสมุดงาน

ในการรวมแผ่นงานหลายแผ่นหรือสมุดงานเป็นแผ่นงานเดียวหรือสมุดงานอาจเป็นเรื่องที่น่าสนใจใน Excel แต่ด้วยไฟล์ รวมกัน ฟังก์ชันใน Kutools สำหรับ Excel คุณสามารถรวมแผ่นงาน / สมุดงานหลายสิบแผ่นไว้ในแผ่นงานหรือสมุดงานเดียวได้นอกจากนี้คุณยังสามารถรวมแผ่นงานเข้าด้วยกันโดยคลิกเพียงไม่กี่ครั้งเท่านั้น  คลิกเพื่อทดลองใช้งานฟรี 30 วันเต็มรูปแบบ!
รวมแผ่น
 
Kutools for Excel: มีโปรแกรมเสริม Excel ที่มีประโยชน์มากกว่า 300 รายการให้ทดลองใช้ฟรีโดยไม่มีข้อ จำกัด ใน 30 วัน

ในการนำเข้าไฟล์ csv ทั้งหมดจากโฟลเดอร์ลงในแผ่นงานเดียวคุณสามารถใช้โค้ด VBA ด้านล่าง

1. เปิดใช้งานแผ่นงานเปล่าแล้วกด Alt + F11 กุญแจเพื่อเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

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

VBA: นำเข้าไฟล์ csv จากโฟลเดอร์ลงในแผ่นงานเดียว

Sub ImportCSVsWithReference()
'UpdatebyKutoolsforExcel20151214
    Dim xSht  As Worksheet
    Dim xWb As Workbook
    Dim xStrPath As String
    Dim xFileDialog As FileDialog
    Dim xFile As String
    On Error GoTo ErrHandler
    Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
    xFileDialog.AllowMultiSelect = False
    xFileDialog.Title = "Select a folder [Kutools for Excel]"
    If xFileDialog.Show = -1 Then
        xStrPath = xFileDialog.SelectedItems(1)
    End If
    If xStrPath = "" Then Exit Sub
    Set xSht = ThisWorkbook.ActiveSheet
    If MsgBox("Clear the existing sheet before importing?", vbYesNo, "Kutools for Excel") = vbYes Then xSht.UsedRange.Clear
    Application.ScreenUpdating = False
    xFile = Dir(xStrPath & "\" & "*.csv")
    Do While xFile <> ""
        Set xWb = Workbooks.Open(xStrPath & "\" & xFile)
        Columns(1).Insert xlShiftToRight
        Columns(1).SpecialCells(xlBlanks).Value = ActiveSheet.Name
        ActiveSheet.UsedRange.Copy xSht.Range("A" & Rows.Count).End(xlUp).Offset(1)
        xWb.Close False
        xFile = Dir
    Loop
    Application.ScreenUpdating = True
    Exit Sub
ErrHandler:
    MsgBox "no files csv", , "Kutools for Excel"
End Sub

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

doc นำเข้าข้อความ csv หลาย xml 4

4 คลิก OKและกล่องโต้ตอบจะปรากฏขึ้นเพื่อเตือนคุณหากล้างเนื้อหาของแผ่นงานที่ใช้งานอยู่ก่อนนำเข้าฉันคลิกที่นี่ ใช่. ดูภาพหน้าจอ:

doc นำเข้าข้อความ csv หลาย xml 5

หลังจากคลิก ใช่ไฟล์ csv ทั้งหมดในโฟลเดอร์ที่เลือกจะถูกนำเข้าไปในแผ่นงานปัจจุบันและวางข้อมูลจากคอลัมน์ A ไปทางขวา ดูภาพหน้าจอ:

doc นำเข้าข้อความ csv หลาย xml 6doc นำเข้าข้อความ csv หลาย xml 7

เคล็ดลับ: หากคุณต้องการวางไฟล์ csv ในแนวนอนในแผ่นงานคุณสามารถใช้ VBA ด้านล่าง

Sub ImportCSVsWithReferenceI()
'UpdatebyKutoolsforExcel20151214
    Dim xSht  As Worksheet
    Dim xWb As Workbook
    Dim xStrPath As String
    Dim xFileDialog As FileDialog
    Dim xFile As String
    Dim xCount As Long
    On Error GoTo ErrHandler
    Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
    xFileDialog.AllowMultiSelect = False
    xFileDialog.Title = "Select a folder [Kutools for Excel]"
    If xFileDialog.Show = -1 Then
        xStrPath = xFileDialog.SelectedItems(1)
    End If
    If xStrPath = "" Then Exit Sub
    Set xSht = ThisWorkbook.ActiveSheet
    If MsgBox("Clear the existing sheet before importing?", vbYesNo, "Kutools for Excel") = vbYes Then
        xSht.UsedRange.Clear
        xCount = 1
    Else
        xCount = xSht.Cells(3, Columns.Count).End(xlToLeft).Column + 1
    End If
    Application.ScreenUpdating = False
    xFile = Dir(xStrPath & "\" & "*.csv")
    Do While xFile <> ""
        Set xWb = Workbooks.Open(xStrPath & "\" & xFile)
        Rows(1).Insert xlShiftDown
        Range("A1") = ActiveSheet.Name
        ActiveSheet.UsedRange.Copy xSht.Cells(1, xCount)
        xWb.Close False
        xFile = Dir
        xCount = xSht.Cells(3, Columns.Count).End(xlToLeft).Column + 1
    Loop
    Application.ScreenUpdating = True
    Exit Sub
ErrHandler:
    MsgBox "no files csv", , "Kutools for Excel"
End Sub 

doc นำเข้าข้อความ csv หลาย xml 8


หากคุณต้องการนำเข้าไฟล์ XML ทั้งหมดจากโฟลเดอร์ลงในแผ่นงานเดียวคุณสามารถใช้โค้ด VBA ด้านล่าง

1. เลือกแผ่นงานเปล่าที่คุณต้องการวางข้อมูลที่นำเข้าแล้วกด Alt + F11 คีย์เพื่อเปิดใช้งาน Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

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

VBA: นำเข้าไฟล์ XML จากโฟลเดอร์ลงในแผ่นงาน

Sub From_XML_To_XL()
'UpdatebyKutoolsforExcel20151214
    Dim xWb As Workbook
    Dim xSWb As Workbook
    Dim xStrPath As String
    Dim xFileDialog As FileDialog
    Dim xFile As String
    Dim xCount As Long
    On Error GoTo ErrHandler
    Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
    xFileDialog.AllowMultiSelect = False
    xFileDialog.Title = "Select a folder [Kutools for Excel]"
    If xFileDialog.Show = -1 Then
        xStrPath = xFileDialog.SelectedItems(1)
    End If
    If xStrPath = "" Then Exit Sub
    Application.ScreenUpdating = False
    Set xSWb = ThisWorkbook
    xCount = 1
    xFile = Dir(xStrPath & "\*.xml")
    Do While xFile <> ""
        Set xWb = Workbooks.OpenXML(xStrPath & "\" & xFile)
        xWb.Sheets(1).UsedRange.Copy xSWb.Sheets(1).Cells(xCount, 1)
        xWb.Close False
        xCount = xSWb.Sheets(1).UsedRange.Rows.Count + 2
        xFile = Dir()
    Loop
    Application.ScreenUpdating = True
    xSWb.Save
    Exit Sub
ErrHandler:
    MsgBox "no files xml", , "Kutools for Excel"
End Sub

3 คลิก วิ่ง หรือ F5 เพื่อเรียกใช้ VBA และเลือกโฟลเดอร์ในกล่องโต้ตอบ popping ดูภาพหน้าจอ:

doc นำเข้าข้อความ csv หลาย xml 9

4 คลิก OKและไฟล์ XML ทั้งหมดในโฟลเดอร์ที่เลือกจะถูกนำเข้าสู่แผ่นงานที่ใช้งานอยู่


หากคุณไม่คุ้นเคยกับ VBA ไม่ต้องกังวลที่นี่ฉันขอแนะนำเครื่องมือที่มีประโยชน์ - Kutools สำหรับ Excel สำหรับคุณ. ด้วยประสิทธิภาพ รวมกัน ยูทิลิตี้คุณสามารถรวมไฟล์ xml หรือไฟล์ csv หลายไฟล์ลงในสมุดงานเดียวหรือหนึ่งแผ่นงาน Excel ได้อย่างรวดเร็ว

Kutools สำหรับ Excel, ที่มีมากกว่า 300 ฟังก์ชั่นที่มีประโยชน์ทำให้งานของคุณง่ายขึ้น 

หลังจากการติดตั้ง Kutools สำหรับ Excel โปรดทำดังนี้:(ดาวน์โหลด Kutools for Excel ฟรีทันที!)

1. ใช้งาน Excel แล้วคลิก Kutools พลัส > รวมกัน. ดูภาพหน้าจอ:
doc รวม 1

2. และใน ขั้นตอนที่ 1 ของการรวม โต้ตอบเลือกตัวเลือกการแยกหนึ่งรายการตามที่คุณต้องการ ดูภาพหน้าจอ:
doc รวม 2

3 คลิก ถัดไป เพื่อไปที่ ขั้นตอนที่ 2 ของการรวมคลิก เพิ่ม เพื่อเพิ่มไฟล์จากโฟลเดอร์ต่างๆหรือไฟล์จากโฟลเดอร์หนึ่งไปยัง สมุดงาน รายการและคุณสามารถระบุแผ่นงานที่คุณต้องการรวมได้ แผ่นงาน รายการส่วนที่ถูกต้อง ดูภาพหน้าจอ:
doc kutools รวมแผ่นงาน 3

4 คลิก ถัดไป ไปยังขั้นตอนสุดท้ายของ รวมกันและคุณสามารถระบุตัวเลือกการรวม
doc kutools รวมแผ่นงาน 4

5 คลิก เสร็จสิ้นกล่องโต้ตอบจะปรากฏขึ้นเพื่อเตือนให้คุณเลือกตำแหน่งที่จะบันทึกผลการรวมใหม่ ดูภาพหน้าจอ:
doc รวม 5

6 คลิก ลด. แผ่นงานที่เพิ่มทั้งหมดรวมกันเป็นแผ่นงานใหม่
doc รวม 6

เคล็ดลับ: กับ รวมกันคุณยังสามารถรวมหลาย ๆ ไฟล์ CSV สร้างหลายโฟลเดอร์หรือหนึ่งโฟลเดอร์เป็นแผ่นเดียวหรือสมุดงาน


หากคุณต้องการส่งออกแต่ละแผ่นเป็นไฟล์ csv / text / pdf ไปยังโฟลเดอร์ Kutools สำหรับ Excel's แยกสมุดงาน ยูทิลิตี้สามารถช่วยคุณได้

หลังจาก ติดตั้งฟรี Kutools สำหรับ Excel โปรดทำดังนี้:

1. เปิดใช้งานสมุดงานที่คุณต้องการส่งออกเวิร์กชีตแล้วคลิก Kutools พลัส > สมุดงาน > แยกสมุดงาน. ดูภาพหน้าจอ:

doc นำเข้าข้อความ csv หลาย xml 10

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

doc นำเข้าข้อความ csv หลาย xml 11

3 คลิก แยก และเลือกโฟลเดอร์ที่จะบันทึกไฟล์แยกในไฟล์ เรียกดูโฟลเดอร์ กล่องโต้ตอบดูภาพหน้าจอ:

doc นำเข้าข้อความ csv หลาย xml 12

4 คลิก OKตอนนี้แผ่นงานที่ตรวจสอบทั้งหมดจะถูกส่งออกเป็นรูปแบบไฟล์ใหม่ในโฟลเดอร์ที่เลือก


บทความญาติ:

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

🤖 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 (36)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Bagaimana caranya menghilangkan header dari tiap-tiap file csv yang terbuka dalam worksheetnya
terima kasih
This comment was minimized by the moderator on the site
Hi there,this is a great tool, but I want to import the various XMl-Files into separate TAB-sheets. Is this possible as the XML's have different header ?
This comment was minimized by the moderator on the site
HelloThe instructions for importing multiple xmls into one tab of an excel document works but was wondering how to get it to line up the columns. My xmls don't all have the same tags. They are set up such that if the xml had no data for some headers(tags) then the header is missing from that xml. Is there a way to get the xmls to import so the same headers from each xml and associated data fall into the same column of excel?
This comment was minimized by the moderator on the site
Hi Experts

I am using the above code for importing multiple xml files into 1 worksheet using VBA however issue i am facing is when rows count reaches 650000 in a worksheet then this code doesn't process rest of the xml files in the folder. It gives an error "no files.xml". Require your kind support
This comment was minimized by the moderator on the site
Hi Team

I am using the code for importing Multiple XML files into single sheet with VBA however issue i am facing is when rows count reaches approximately 650000, then it doesn't processes rest of the xml files in the folder and gives an error that no xml files. Need your support to increase this count.
This comment was minimized by the moderator on the site
Hi, is there any way to import multiple csv files with semicolon as separator? Thank you!
PS Nice article!
This comment was minimized by the moderator on the site
Hello - I've used your VBA codes to extract data from multiple CSV files to excel file (the code on this page) and convert csv files to excel files ( this one: https://www.extendoffice.com/documents/excel/4615-excel-batch-convert-csv-to-xls-xlsx.html), with great results. They helped me save a lot of time.

However, I notice a common problem with both of these types of codes. To clarify, my system is set up to use the European standards for dates, while some of the CSV files I received for my work contain dates in US standards. The first problem is, when I extract or convert data from a CSV file that contains dates in US format, all of those dates are reversed (matching the EU standards used by my system). This is great but it also caused me troubles since I didn't know the codes would reverse the dates for me, so I went on ahead and did the same thing again. The second problem is, for the CSV files that contain dates already in the same format as the one used by my system (EU standards), only the ambiguous dates are reversed (i.e 04/05/2019 - 05/04/2019), while the ones that are too obvious, remain unchanged (i.e 30/04/2019).

What I would like the codes to do, is the exact same thing as they are shown here, only that they should copy and paste the data (especially dates) in the exact formats used in the original files. This would help prevent any possible confusions and mistakes. I would like to learn VBA so I can one day write my own codes, but for now, I'm not even able to modify parts of the existing codes to suit my needs. So if you can help, please tell me where I should put the modified codes (that you come up with) to the existing codes. I appreciate all feedback & support I can get. Thank you all!
This comment was minimized by the moderator on the site
Hi Marshall, in the Workbooks.Open method, add in the option Local:=True.

i.e.
Set xWb = Workbooks.Open(xStrPath & "\" & xFile, Local:=True)
This comment was minimized by the moderator on the site
Hi Robert,
It's me again. It took me a while to actually have the time to figure out which part of the code the "Local:True" part should be added to. The result turned out great as the dates are no longer reversed. Thank you!
For anyone having the same problem, just change this line:
Set xWb = Workbooks.OpenXML(xStrPath & "\" & xFile)

To this:
Set xWb = Workbooks.Open(xStrPath & "\" & xFile, Local:=True)
This comment was minimized by the moderator on the site
Thank you very much Robert. Sorry I couldn't reply to you any earlier. I didn't get any notification until now. I will try this out and come back to you later to let you know if this works.
This comment was minimized by the moderator on the site
Hi - I'm using the import all csv files into one file listed above "Import Multiple Csv Files From A Folder Into A Single Sheet With VBA"- i'd like to define the folder it collects the data from without having to manually choose it. Can this be done? thanks - SW.
This comment was minimized by the moderator on the site
Hi, Scott W, I found a VBA code may can help you.
Option Explicit

Sub ImportCSVsWithReference()
'Author: Jerry Beaucaire
'Date: 10/16/2010
'Summary: Import all CSV files from a folder into a single sheet
' adding a field in column A listing the CSV filenames

Dim wbCSV As Workbook
Dim wsMstr As Worksheet: Set wsMstr = ThisWorkbook.Sheets("Sheet1")
Dim fPath As String: fPath = " C:\Users\DT168\Desktop\New folder\" 'path to CSV files, include the final \
Dim fCSV As String

If MsgBox("Clear the existing sheet before importing?", vbYesNo, "Clear?") _
= vbYes Then wsMstr.UsedRange.Clear

Application.ScreenUpdating = False 'speed up macro

fCSV = Dir(fPath & "*.csv") 'start the CSV file listing

Do While Len(fCSV) > 0
'open a CSV file
Set wbCSV = Workbooks.Open(fPath & fCSV)
'insert col A and add CSV name
Columns(1).Insert xlShiftToRight
Columns(1).SpecialCells(xlBlanks).Value = ActiveSheet.Name
'copy date into master sheet and close source file
ActiveSheet.UsedRange.Copy wsMstr.Range("A" & Rows.Count).End(xlUp).Offset(1)
wbCSV.Close False
'ready next CSV
fCSV = Dir
Loop

Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
How to eliminate duplicate header and CSV file name column. Please do help....I have gone through several articles, but unfortunately all give same result.
This comment was minimized by the moderator on the site
Thank you. This site has been a big help. I have one issue I cannot figure out. I am trying to import multiple csv files into an excel separate sheets in excel and have each sheet renamed after the file name of the csv file. I know this was covered below for a txt file but I am working with csv files. Thanks in advance.
This comment was minimized by the moderator on the site
Hi! I used the code to merge multiple XML files into one, but unfortunately the columns got messed up. The 5 files being merged all had the same format. Is there anyway to fix this? I also was wondering if there was a way to get rid of the headers that are duplicated when the files are merged. Thank you!
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations