메인 컨텐츠로 가기

여러 / 모든 시트를 저장하고 Excel에서 별도의 CSV 또는 텍스트 파일로 내보내는 방법은 무엇입니까?

Excel을 사용할 때 다른 이름으로 저장 기능을 사용하여 워크시트를 csv 또는 텍스트 파일로 수동으로 저장할 수 있습니다. 그러나 통합 문서의 여러 또는 모든 워크시트를 분리된 csv 또는 텍스트 파일로 변환하려면 어떻게 해야 합니까? 이 기사에서는 여러 시트 또는 모든 시트를 분리된 csv 또는 텍스트 파일로 저장하거나 변환하는 방법을 보여줍니다.

VBA 코드를 사용하여 모든 시트를 csv 또는 텍스트 파일로 저장, 내보내기 또는 변환
Excel 용 Kutools를 사용하여 여러 / 모든 시트를 CSV 또는 텍스트 파일로 저장, 내보내기 또는 변환


VBA 코드를 사용하여 모든 시트를 csv 또는 텍스트 파일로 저장, 내보내기 또는 변환

아래 VBA 코드를 사용하면 통합 문서의 모든 워크 시트를 별도의 csv 또는 텍스트 파일에 저장할 수 있습니다. 다음과 같이하십시오.

모든 시트를 CSV 파일로 내보내기 또는 변환

1. 프레스 다른 + F11 동시에 열려면 키 Microsoft Visual Basic 응용 프로그램 창.

2. 에서 Microsoft Visual Basic 응용 프로그램 창을 클릭합니다 끼워 넣다 > 모듈. 그런 다음 다음 코드를 복사하여 모듈 창.

VBA 코드 : 모든 시트를 분리 된 csv 파일로 내보내기

Sub ExportSheetsToCSV()
	Dim xWs As Worksheet
	Dim xcsvFile As String
	For Each xWs In Application.ActiveWorkbook.Worksheets
		xWs.Copy
		xcsvFile = CurDir & "\" & xWs.Name & ".csv"
		Application.ActiveWorkbook.SaveAs Filename: = xcsvFile, _
		FileFormat: = xlCSV, CreateBackup: = False
		Application.ActiveWorkbook.Saved = True
		Application.ActiveWorkbook.Close
	Next
End Sub

3. 누르세요 F5 코드를 실행하는 키입니다. 내 보낸 모든 csv 파일이 서류 폴더. 스크린 샷보기 :

모든 시트를 텍스트 파일로 내보내기 또는 변환

다음 코드는 통합 문서의 모든 시트를 별도의 텍스트 파일로 내보내거나 변환하는 데 도움이 될 수 있습니다.

VBA 코드 : 모든 시트를 분리 된 텍스트 파일로 내보내기

Sub ExportSheetsToText()
	Dim xWs As Worksheet
	Dim xTextFile As String
	For Each xWs In Application.ActiveWorkbook.Worksheets
		xWs.Copy
		xTextFile = CurDir & "\" & xWs.Name & ".txt"
		Application.ActiveWorkbook.SaveAs Filename: = xTextFile, FileFormat: = xlText
		Application.ActiveWorkbook.Saved = True
		Application.ActiveWorkbook.Close
	Next
End Sub

내 보낸 텍스트 파일은 서류 폴더. 스크린 샷보기 :


Excel 용 Kutools를 사용하여 여러 / 모든 시트를 CSV 또는 텍스트 파일로 저장, 내보내기 또는 변환

You는 여러 시트 또는 모든 시트를 Excel의 개별 csv 파일, 텍스트 파일 또는 xls 파일 형식으로 빠르게 내보내거나 변환 할 수 있습니다. 통합 문서 분할 ~의 유용성 Excel 용 Kutools.

신청하기 전에 Excel 용 Kutools, 제발 먼저 다운로드하여 설치하십시오..

1. 클릭 쿠툴즈 플러스 > 통합 문서 > 통합 문서 분할. 스크린 샷보기 :

2. 에서 통합 문서 분할 대화 상자 :

  • 1). 모든 시트를 csv 또는 텍스트 파일로 변환하려면 모든 시트 이름을 워크 시트 이름 상자; 여러 시트를 변환하려는 경우 계속 확인하고 변환하지 않을 다른 시트는 선택 취소하십시오.
  • 2). 에서 옵션 섹션에서 형식으로 저장 상자를 선택한 다음 유니 코드 텍스트 (* .txt) or CSV (Macintosh) (*. csv) 드롭 다운 목록에서
  • 3). 클릭 스플릿 버튼을 클릭합니다.

3. 에서 폴더 찾아보기 대화 상자에서 내 보낸 파일을 저장할 폴더를 지정한 다음 OK 버튼을 클릭합니다.

이제 모든 시트 또는 지정된 시트가 분리 된 csv 또는 텍스트 파일로 변환되고 위에서 지정한 폴더에서 찾습니다.

  이 유틸리티의 무료 평가판 (30 일)을 받으려면 그것을 다운로드하려면 클릭하십시오을 클릭 한 다음 위 단계에 따라 작업 적용으로 이동합니다.


Excel 용 Kutools를 사용하여 여러 / 모든 시트를 CSV 또는 텍스트 파일로 저장, 내보내기 또는 변환

최고의 사무 생산성 도구

🤖 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 (38)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi, thanks for the VBA, i have a problem with the VBA for export to text file, as the VBA run the txt file got generated, but the inside data is not exactly like the excel data, for example my data include character quotation mark, and the exported data became double quotation mark, plus the beginning and the ending of the text file there are quotation mark, here's the excel and the txt file that i meant :
excel : Start Chrome https://xxx/tap_inbox_sparepart_act.asp?proses_id=202300102027800&act=akseptoraksep"&"alasan=ok
text file : "Start Chrome https://xxx/tap_inbox_sparepart_act.asp?proses_id=202300102027800&act=akseptoraksep""&""alasan=ok"

Thanks in advanced :)
This comment was minimized by the moderator on the site
Hi Nicky,

I tested this code, but could not reproduce the problem in my case. And the file you provided didn't open. Can you upload your file using the "upload attachment" link below?
This comment was minimized by the moderator on the site
The VBA code works nicely. Equivalent C# code in a VSTO workbook project emits empty .csv files.


void SaveSomeWorksheetsAsCsvFiles() {
    string[] worksheetNames = new[] { "Sheet1", "Sheet2", "Sheet3" };
    foreach (var worksheet in worksheetNames.Select(_ => Globals.ThisWorkbook.Sheets[_] as Excel.Worksheet)) {
        worksheet.Copy();
        string fullName = @"C:\Users\....\Staging" + $".{worksheet.Name}.csv";
        this.SaveAs(fullName, XlFileFormat.xlCSV);
        Application.ActiveWorkbook.Saved = true;
        Application.ActiveWorkbook.Close();
    }
}
This comment was minimized by the moderator on the site
Hi Calvin,
We do not support programming languages other than VBA. Sorry for the inconvenience.
This comment was minimized by the moderator on the site
Hi, thanks for the great code (Export all sheets to separated Text files), using it a lot. Just ran into a workbook where it won't work, debugger says line xWs.Copy is problem, popup says method copy of a workbook failed. Is there any restrictions concerning a worksheet name or something similar, like no merged cells etc..?

Thanks for a reply :)
This comment was minimized by the moderator on the site
HI BI,
Does your worksheet contain a pivot table? Can you provide us with your data for tesing? If you don't mind, upload your sample file here.
This comment was minimized by the moderator on the site
Hi, thanks for the great code it is awesome(Export all sheets to separated Text files)! Used it on many occasions but ran into a file where it won't work, debugger says runtime error 1004 and that method copy of a worksheet failed and marks line xWs.Copy. Is there any rule concerning a worksheet name that would not allow code to run?
This comment was minimized by the moderator on the site
Thanks! I used this to save all the sheets of my .xlsx file into differents .xlsx
Sub ExportSheetsToXLSX()
Dim xWs As Worksheet
Dim xcsvFile As String
For Each xWs In Application.ActiveWorkbook.Worksheets
xWs.Copy
xlsxFile = CurDir & "\" & xWs.Name & ".xlsx"
Application.ActiveWorkbook.SaveAs Filename:=xlsxFile, _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Application.ActiveWorkbook.Saved = True
Application.ActiveWorkbook.Close
Next
End Sub
This comment was minimized by the moderator on the site
how would I change the code to have it save in a different file format such as an xlsx? or ASCII.
This comment was minimized by the moderator on the site
So, this is great! BUT, what if I need to split a workbook into .csv but for PC, not MAC? If anyone has a way of doing it, please help me out. I will be very grateful.
This comment was minimized by the moderator on the site
Hi,
The first VBA code in this post can do you a favor.
This comment was minimized by the moderator on the site
Is there a way to use this code to export only a certain range to a .csv file of each sheet in a book?
This comment was minimized by the moderator on the site
Hi,
The VBA code in this article may do you a favor: https://www.extendoffice.com/documents/excel/2897-excel-export-range-to-csv.html
This comment was minimized by the moderator on the site
Hello,
thank you so much for a great macro, it works like a charm! But I have a question, what if I would like to save this macro (CSV version) on PERSONAL.xlsb as to make it available on any excel instance?

When I try, CurDir takes the PERSONAL directory, instead of the active worksheet one...

Thank you for any help!
This comment was minimized by the moderator on the site
Hi Mirko,
Method in this article can do you a favor: https://trumpexcel.com/personal-macro-workbook/.
This comment was minimized by the moderator on the site
If you just want to convert multiple sheets, keep checking them and going to uncheck other sheets you don’t want to convert
sir for thuis step do you have macro
This comment was minimized by the moderator on the site
Good day,
Can't help with VBA code for this. Why not try the Split Workbook utility we provide in the post? It will save your time and you will love it.
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