메인 컨텐츠로 가기

여러 Excel 파일을 Excel에서 CSV 파일로 일괄 변환하는 방법은 무엇입니까?

Excel에서 다른 이름으로 저장 기능을 사용하여 통합 문서를 CSV 파일로 변환 할 수 있지만 여러 Excel 파일을 별도의 CSV 파일로 일괄 변환하는 방법을 알고 계십니까? 이 기사에서는 폴더의 모든 Excel 파일을 Excel의 CSV 파일로 일괄 변환하는 VBA 코드를 소개합니다.

VBA를 사용하여 폴더의 Excel 파일을 CSV 파일로 일괄 변환

Excel 용 Kutools를 사용하여 통합 문서 시트를 별도의 CSV 파일로 변환좋은 생각 3


VBA를 사용하여 폴더의 Excel 파일을 CSV 파일로 일괄 변환

Excel에는 VBA를 제외하고는이 작업을 빠르게 해결할 수있는 기본 제공 기능이 없습니다.

1. Excel을 활성화하고 Alt + F11 열쇠 열림 응용 프로그램 용 Microsoft Visual Basic 창.

2. 클릭 끼워 넣다 > 모듈 새 모듈을 만듭니다.

3. 아래 코드를 복사하여 새 모듈 창에 붙여 넣습니다.

VBA : Excel 파일을 CSV로 일괄 변환

Sub WorkbooksSaveAsCsvToFolder()

'UpdatebyExtendoffice20181031

Dim xObjWB As Workbook

Dim xObjWS As Worksheet

Dim xStrEFPath As String

Dim xStrEFFile As String

Dim xObjFD As FileDialog

Dim xObjSFD As FileDialog

Dim xStrSPath As String

Dim xStrCSVFName As String

Dim xS  As String

    Application.ScreenUpdating = False

    Application.EnableEvents = False

    Application.Calculation = xlCalculationManual

    Application.DisplayAlerts = False

    On Error Resume Next

Set xObjFD = Application.FileDialog(msoFileDialogFolderPicker)

    xObjFD.AllowMultiSelect = False

    xObjFD.Title = "Kutools for Excel - Select a folder which contains Excel files"

    If xObjFD.Show <> -1 Then Exit Sub

    xStrEFPath = xObjFD.SelectedItems(1) & "\"

    Set xObjSFD = Application.FileDialog(msoFileDialogFolderPicker)

 
    xObjSFD.AllowMultiSelect = False

    xObjSFD.Title = "Kutools for Excel - Select a folder to locate CSV files"

    If xObjSFD.Show <> -1 Then Exit Sub

    xStrSPath = xObjSFD.SelectedItems(1) & "\"


    xStrEFFile = Dir(xStrEFPath & "*.xls*")


    Do While xStrEFFile <> ""

       xS = xStrEFPath & xStrEFFile

        Set xObjWB = Application.Workbooks.Open(xS)

        xStrCSVFName = xStrSPath & Left(xStrEFFile, InStr(1, xStrEFFile, ".") - 1) & ".csv"

        xObjWB.SaveAs Filename:=xStrCSVFName, FileFormat:=xlCSV

        xObjWB.Close savechanges:=False

        xStrEFFile = Dir

  Loop

    Application.Calculation = xlCalculationAutomatic

    Application.EnableEvents = True

    Application.ScreenUpdating = True

    Application.DisplayAlerts = True

End Sub

4. 프레스 F5 키, 첫 번째 팝업 대화 상자에서 CSV 파일로 변환하려는 Excel 파일이 포함 된 폴더를 선택합니다.
csv 1에 문서 배치

5. 클릭 OK을 클릭 한 다음 두 번째 팝업 대화 상자에서 CSV 파일을 저장할 폴더를 선택합니다.
csv 2에 문서 배치

6. 클릭 OK, 이제 폴더의 Excel 파일이 CSV 파일로 변환되어 다른 폴더에 저장되었습니다.
csv 3에 문서 배치


Excel 용 Kutools를 사용하여 통합 문서 시트를 별도의 CSV 파일로 변환

아시다시피 다른 이름으로 저장 기능을 사용하여 전체 통합 문서를 Excel에서 하나의 CSV 파일로만 변환 할 수 있습니다. 그러나 어떤 경우에는 단일 시트를 CSV 파일로 변환하려고합니다.이 경우에는 통합 문서 분할 ~의 유용성 Excel 용 Kutools 당신을 도울 수 있습니다.

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

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

1. 시트를 별도의 CSV 파일로 변환하려는 통합 문서를 활성화하고 쿠툴즈 플러스 > 통합 문서 > 통합 문서 분할.
csv 4에 문서 배치

2. 에서 통합 문서 분할 대화 상자에서 분할하려는 시트 이름을 확인하고 (모든 시트가 기본적으로 선택되어 있음) 다른 이름으로 저장 입력, 선택 CSV (Macintosh) (*. CSV) 드롭 다운 목록에서
csv 5에 문서 배치

3. 클릭 스플릿 튀어 나오다 폴더 찾아보기 대화 상자에서 CSV 파일을 저장할 폴더를 선택하거나 만듭니다.
csv 6에 문서 배치

4. 클릭 OK, 이제 통합 문서가 별도의 CSV 파일로 분할되었습니다.
csv 7에 문서 배치

최고의 사무 생산성 도구

🤖 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 (37)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Thank you, lifesaver, I have no coding experience but this seems to work for my purposes perfectly.

Is it possible to set the directory for the read xls and write csv so that you don't have to select it each time? My files are being written to the same location each day automatically and I'm trying to automate this conversion to csv as much as I can.

Thanks,
This comment was minimized by the moderator on the site
This is a great peace of coding, but I just realised that it is inverting the dates for me. (we are in UK) and when the date shows 23/03/78 in the CSV the date comes out as 3/23/78.

Is doesn't happen to all lives. Eg if the date was showing 1/2/11 it would stay the same. But if it was 01/02/11 it would chnage to 02/01/11

Any suggestions?
This comment was minimized by the moderator on the site
Batch script not accept unicode character in file name or in work sheet. I've changed
xObjWB.SaveAs Filename:=xStrCSVFName, FileFormat:=[b]xlCSV[/b]


to

xObjWB.SaveAs Filename:=xStrCSVFName, FileFormat:=[b]xlCSVUTF8[/b]. But [b]xlCSVUTF8[/b] seems not supported in older excel version (before 2016)


Batch script not support files in recursive folders too.
This comment was minimized by the moderator on the site
Hallo,

ich habe den VBA-Code vor einem Jahr ohne Probleme angewendet. Jetzt funktioniert es nicht mehr.
Es gibt einen Laufzeitfehler 1004 mit dem Hinweis: "Die Methode 'calculation' für das Objekt '_Application' ist fehlgeschlagen."

Debuggen verweist auf die Zeile "Application.Calculation = xlCalculationManual".

Ich würde mich sehr freuen, wenn jemand weiterhelfen könnte.

LG, Max
This comment was minimized by the moderator on the site
Hi, Gast, pleae check if the code you copied is correct firstly, there is no "_" in the code. If you have checked all code is correct, you can remove the code line
Application.Calculation = xlCalculationManual then try again. Please notice that there are two lines Application.Calculation = xlCalculationManual in the code.
This comment was minimized by the moderator on the site
Hallo,

vor einem Jahr habe ich den VBA-Code ohne Probleme ausgeführt. Heute wollte ich es nochmal versuchen, leider gibt es einen Laufzeitfehler 1004 mit dem Hinweis
"Die Methode 'Calculation' ist für Objekt '_Application' fehlgeschlagen."

Debuggen verweist auf folgende Zeile:
Application.Calculation = xlCalculationManual

Kann jemand weiterhelfen?

LG, Max
This comment was minimized by the moderator on the site
Hi,
I'm facing some problems when using the script
Ho can I change the delimiter in the script because the delimiter in csv output is in comma (,)
I need the delimiter not in comma because my datasets consist a lot of commas.


Thank you
This comment was minimized by the moderator on the site
Ajouter Local:=True à cette ligne:
xObjWB.SaveAs Filename:=xStrCSVFName, FileFormat:=xlCSV, Local:=True

Permet de prendre le séparateur de votre système, moi c'est point-virgule ;
This comment was minimized by the moderator on the site
Hi, How can i change the delimiter ?
In the script above, the delimiter is comma (,).
Thank you :D
This comment was minimized by the moderator on the site
2019버전입니다.
게시글 그대로 실행해봤지만 아무것도 일어나지 않았습니다 ..
This comment was minimized by the moderator on the site
Hi, YOY, I have tested the VBA in Professional Plus Excel 2019, it works smoothly and correctly. Should you give me more details about your files, such as detailed verison, the contents of files you want to convert?
This comment was minimized by the moderator on the site
Bom Dia!!

muito top esse codigo, porem estou com o problema abaixo

Tem como salvar em formato "CSV (separado por vírgulas) (*.csv)", pois ao executar esse código meus arquivos ficam com "," no formato que eu preciso eles não ficam com essa vírgula
This comment was minimized by the moderator on the site
Same issue with me. Running latest office 365 but nothing happens after setting the two folders dialog boxes.
This comment was minimized by the moderator on the site
Hi, Doc SJ, thanks for your reminder, I have check the VBA code, it has some issues in Office 365, now I have updated the VBA, please try it again.
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