메인 컨텐츠로 가기

Excel에서 여러 csv / text / xml 파일을 빠르게 일괄 가져 오는 방법은 무엇입니까?

Excel에서 통합 문서를 csv 파일, 텍스트 파일 또는 xml 파일로 저장하는 데 묶여있을 수 있지만 폴더에서 여러 csv / text / xml 파일을 통합 문서 또는 워크 시트로 가져 오려고 시도한 적이 있습니까? 이 기사에서는 일괄 가져 오기를 빠르게하는 몇 가지 방법을 소개합니다.

VBA를 사용하여 폴더에서 여러 텍스트 파일을 통합 문서의 각 워크 시트로 가져옵니다.

VBA를 사용하여 폴더의 여러 csv 파일을 단일 시트로 가져 오기

VBA를 사용하여 폴더의 여러 xml 파일을 단일 시트로 가져 오기

Excel 용 Kutools를 사용하여 여러 xml / csv 파일을 시트 또는 통합 문서로 가져 오거나 결합 좋은 생각 3

Excel 용 Kutools를 사용하여 각 시트를 csv / text / pdf로 폴더에 내보내기좋은 생각 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를 실행하고 팝업 대화 상자에서 텍스트 파일을 가져올 폴더를 선택하십시오. 스크린 샷보기 :

문서 가져 오기 여러 CSV 텍스트 XML 1

4. 그리고 클릭 OK, 선택한 폴더의 각 텍스트 파일을 활성 통합 문서의 하나의 워크 시트로 가져 왔습니다. 스크린 샷보기 :

문서 가져 오기 여러 CSV 텍스트 XML 2문서 가져 오기 여러 CSV 텍스트 XML 3

여러 시트 / 통합 문서를 하나의 단일 시트 또는 통합 문서로 쉽게 결합

여러 시트 또는 통합 문서를 하나의 시트 또는 통합 문서로 결합하는 것은 Excel에서 지루할 수 있지만 결합 Excel 용 Kutools의 기능을 사용하면 수십 개의 시트 / 통합 문서를 하나의 시트 또는 통합 문서로 병합 할 수 있으며 몇 번의 클릭만으로 시트를 하나로 통합 할 수 있습니다.  모든 기능을 갖춘 30일 무료 평가판을 보려면 클릭하세요!
시트 결합
 
Excel 용 Kutools : 300 개 이상의 편리한 Excel 추가 기능으로 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 파일을 가져올 폴더를 선택하는 대화 상자가 나타납니다. 스크린 샷보기 :

문서 가져 오기 여러 CSV 텍스트 XML 4

4. 클릭 OK을 클릭하면 가져 오기 전에 활성 워크 시트의 내용을 지 울지 알려주는 대화 상자가 나타납니다. 여기에서 가능. 스크린 샷보기 :

문서 가져 오기 여러 CSV 텍스트 XML 5

클릭하면 가능, 선택한 폴더의 모든 csv 파일을 현재 시트로 가져오고 A 열의 데이터를 오른쪽에 배치합니다. 스크린 샷보기 :

문서 가져 오기 여러 CSV 텍스트 XML 6문서 가져 오기 여러 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 

문서 가져 오기 여러 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를 실행하고 팝업 대화 상자에서 폴더를 선택합니다. 스크린 샷 참조 :

문서 가져 오기 여러 CSV 텍스트 XML 9

4. 클릭 OK, 선택한 폴더의 모든 XML 파일을 활성 시트로 가져옵니다.


VBA에 익숙하지 않더라도 걱정하지 마십시오. 여기에 편리한 도구를 소개합니다. Excel 용 Kutools 당신을 위해. 강력한 결합 유틸리티를 사용하면 여러 xml 파일 또는 csv 파일을 하나의 통합 문서 또는 하나의 Excel 시트로 빠르게 결합 할 수 있습니다.

Excel 용 Kutools, 이상과 300 편리한 기능으로 작업이 더 쉬워집니다. 

설치 후 Excel 용 Kutools는 다음과 같이하십시오.(지금 Excel 용 Kutools 무료 다운로드!)

1. 활성 Excel을 클릭하고 쿠툴즈 플러스 > 결합. 스크린 샷보기 :
문서 결합 1

2. 그리고 결합의 1 단계 대화 상자에서 필요에 따라 하나의 분리 옵션을 선택합니다. 스크린 샷보기 :
문서 결합 2

3. 클릭 다음 보기 가기 위해 결합의 2 단계클릭 추가 다양한 폴더의 파일 또는 한 폴더의 파일을 통합 문서 목록에서 결합 할 시트를 지정할 수도 있습니다. 워크 시트 오른쪽 섹션 목록. 스크린 샷보기 :
doc kutools 결합 시트 3

4. 클릭 다음 보기 마지막 한 단계까지 결합, 결합 옵션을 지정할 수 있습니다.
doc kutools 결합 시트 4

5. 클릭 마감재 , 새로운 결합 결과를 저장할 위치를 선택하라는 대화 상자가 나타납니다. 스크린 샷보기 :
문서 결합 5

6. 클릭 찜하기. 모든 추가 시트가 새 단일 시트로 결합되었습니다.
문서 결합 6

팁 :결합, 여러 CSV 파일 여러 폴더 또는 하나의 폴더를 하나의 시트 또는 통합 문서로 만듭니다.


각 시트를 csv / text / pdf 파일로 폴더에 내보내려면 Excel 용 Kutools통합 문서 분할 유틸리티는 당신을 위해 호의를 베풀 수 있습니다.

무료 설치 Excel 용 Kutools는 다음과 같이하십시오.

1. 워크 시트를 내보낼 통합 문서를 활성화하고 쿠툴즈 플러스 > 통합 문서 > 통합 문서 분할. 스크린 샷보기 :

문서 가져 오기 여러 CSV 텍스트 XML 10

2. 에서 통합 문서 분할 대화 상자에서 내 보내야하는 시트 이름을 확인할 수 있으며 기본적으로 모든 시트가 선택되어 있으며 저장 형식 지정 아래 드롭 다운 목록에서 저장할 파일 형식을 선택합니다. 스크린 샷보기 :

문서 가져 오기 여러 CSV 텍스트 XML 11

3. 클릭 스플릿 분할 파일을 저장할 폴더를 선택하십시오. 폴더 찾아보기 대화 상자, 스크린 샷 참조 :

문서 가져 오기 여러 CSV 텍스트 XML 12

4. 클릭 OK, 이제 선택한 모든 시트가 선택한 폴더의 새 파일 형식으로 내보내집니다.


관련 기사 :

최고의 사무 생산성 도구

🤖 Kutools AI 보좌관: 다음을 기반으로 데이터 분석을 혁신합니다. 지능형 실행   |  코드 생성  |  사용자 정의 수식 만들기  |  데이터 분석 및 차트 생성  |  Kutools 기능 호출...
인기 기능: 중복 항목 찾기, 강조 표시 또는 식별   |  빈 행 삭제   |  데이터 손실 없이 열이나 셀 결합   |   수식없이 반올림 ...
슈퍼 조회: 다중 기준 VLookup    다중 값 VLookup  |   여러 시트에 걸친 VLookup   |   퍼지 조회 ....
고급 드롭다운 목록: 드롭다운 목록을 빠르게 생성   |  종속 드롭다운 목록   |  다중 선택 드롭 다운 목록 ....
열 관리자: 특정 개수의 열 추가  |  열 이동  |  Toggle 숨겨진 열의 가시성 상태  |  범위 및 열 비교 ...
특색 지어진 특징: 그리드 포커스   |  디자인보기   |   큰 수식 바    통합 문서 및 시트 관리자   |  리소스 라이브러리 (자동 텍스트)   |  날짜 선택기   |  워크 시트 결합   |  셀 암호화/해독    목록으로 이메일 보내기   |  슈퍼 필터   |   특수 필터 (굵게/기울임꼴/취소선 필터링...) ...
상위 15개 도구 세트12 본문 도구 (텍스트 추가, 문자 제거,...)   |   50+ 거래차트 유형 (Gantt 차트,...)   |   40+ 실용 방식 (생일을 기준으로 나이 계산,...)   |   19 삽입 도구 (QR 코드 삽입, 경로에서 그림 삽입,...)   |   12 매출 상승 도구 (숫자를 단어로, 환율,...)   |   7 병합 및 분할 도구 (고급 결합 행, 셀 분할,...)   |   ... 그리고 더

Excel용 Kutools로 Excel 기술을 강화하고 이전과는 전혀 다른 효율성을 경험해 보세요. Excel용 Kutools는 생산성을 높이고 시간을 절약하기 위해 300개 이상의 고급 기능을 제공합니다.  가장 필요한 기능을 얻으려면 여기를 클릭하십시오...

상품 설명


Office Tab은 Office에 탭 인터페이스를 제공하여 작업을 훨씬 쉽게 만듭니다.

  • Word, Excel, PowerPoint에서 탭 편집 및 읽기 사용, Publisher, Access, Visio 및 Project.
  • 새 창이 아닌 동일한 창의 새 탭에서 여러 문서를 열고 만듭니다.
  • 생산성을 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