메인 컨텐츠로 가기

Word 문서를 txt 파일로 일괄 변환하는 방법은 무엇입니까?

이 기사에서는 특정 폴더의 모든 Word 문서를 Word에서 별도의 TXT 파일로 일괄 변환하는 방법에 대해 설명합니다.

VBA를 사용하여 Word 문서를 txt 파일로 일괄 변환


VBA를 사용하여 Word 문서를 txt 파일로 일괄 변환

아래 VBA 코드는 특정 폴더의 모든 Word 문서를 한 번에 txt 파일로 변환하는 데 도움이 될 수 있습니다. 다음과 같이하십시오.

1. Word 문서에서 다른 + F11 키를 눌러 응용 프로그램 용 Microsoft Visual Basic 창.

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

VBA 코드 : Word 문서를 txt 파일로 일괄 변환

Sub ConvertDocumentsToTxt()
'Updated by Extendoffice 20181123
    Dim xIndex As Long
    Dim xFolder As Variant
    Dim xFileStr As String
    Dim xFilePath As String
    Dim xDlg As FileDialog
    Dim xActPath As String
    Dim xDoc As Document
    Application.ScreenUpdating = False
    Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)
    If xDlg.Show <> -1 Then Exit Sub
    xFolder = xDlg.SelectedItems(1)
    xFileStr = Dir(xFolder & "\*.doc")
    xActPath = ActiveDocument.Path
    While xFileStr <> ""
        xFilePath = xFolder & "\" & xFileStr
        If xFilePath <> xActPath Then
            Set xDoc = Documents.Open(xFilePath, AddToRecentFiles:=False, Visible:=False)
            xIndex = InStrRev(xFilePath, ".")
            Debug.Print Left(xFilePath, xIndex - 1) & ".txt"
            xDoc.SaveAs Left(xFilePath, xIndex - 1) & ".txt", FileFormat:=wdFormatText, AddToRecentFiles:=False
            xDoc.Close True
        End If
        xFileStr = Dir()
    Wend
    Application.ScreenUpdating = True
End Sub

3. 누르세요 F5 코드를 실행하는 키입니다.

4. 에서 검색 창에서 txt 파일로 변환 할 Word 문서가 들어있는 폴더를 선택하고 OK 단추. 스크린 샷보기 :

그러면 선택한 폴더의 모든 문서가 한 번에 txt 파일로 변환되는 것을 볼 수 있습니다. 스크린 샷보기 :

최고의 사무 생산성 도구

Word 용 Kutools - Over로 단어 경험을 향상시키세요 100 놀라운 기능!

🤖 Kutools AI 도우미: AI로 글쓰기를 변화시키세요 - 콘텐츠 생성  /  텍스트 다시 쓰기  /  문서 요약  /  정보 문의 문서 기반, 모두 Word 내에서

📘 문서 숙달: 페이지 분할  /  문서 병합  /  다양한 형식으로 선택 항목 내보내기(PDF/TXT/DOC/HTML...)  /  PDF로 일괄 변환  /  페이지를 이미지로 내보내기  /  한 번에 여러 파일 인쇄...

컨텐츠 편집: 일괄 찾기 및 바꾸기 여러 파일에 걸쳐  /  모든 사진 크기 조정  /  테이블 행과 열 바꾸기  /  표를 텍스트로 변환...

🧹 손쉬운 청소: 쓸어버리다 추가 공간  /  섹션 나누기  /  모든 헤더  /  텍스트 상자  /  하이퍼 링크  / 더 많은 제거 도구를 보려면 다음 페이지를 방문하세요. 그룹 제거...

광고 삽입물: 삽입 천 단위 구분 기호  /  확인란  /  라디오 버튼  /  QR 코드  /  바코드  /  대각선 표  /  방정식 캡션  /  이미지 캡션  /  테이블 캡션  /  여러 장의 사진  / 더 자세히 알아보세요. 그룹 삽입...

🔍 정밀한 선택: 핀포인트 특정 페이지  /  테이블  /  모양  /  제목 단락  / 탐색 기능 향상 배우기 기능 선택...

스타 강화: 어떤 위치로든 빠르게 이동  /  반복되는 텍스트 자동 삽입  /  문서 창 간을 원활하게 전환합니다.  /  11 변환 도구...

👉 이러한 기능을 사용해 보고 싶으신가요? Word 용 Kutools는 다음을 제공합니다. 60 일 무료 사용, 제한 없음! 🚀
 
Comments (22)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
Vielen Dank, das ist wirklich sehr hilfreich! Ich werde auf Deine Seite bei der nächsten Gelegenheit verweisen.
Gruß
Uli
This comment was minimized by the moderator on the site
Hi, this works perfectly. Is there a way to choose a different encoding format of the TXT (UTF-8 instead of Windows for example) ?
This comment was minimized by the moderator on the site
Hi Simon,
The following VBA code helps to convert all Word documents in a specified folder to UTF-8 .txt files
Sub ConvertDocumentsToTxt()
'Updated by Extendoffice 20201031
    Dim xIndex As Long
    Dim xFolder As Variant
    Dim xFileStr As String
    Dim xFilePath As String
    Dim xDlg As FileDialog
    Dim xActPath As String
    Dim xDoc As Document
    Application.ScreenUpdating = False
    Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)
    If xDlg.Show <> -1 Then Exit Sub
    xFolder = xDlg.SelectedItems(1)
    xFileStr = Dir(xFolder & "\*.doc")
    xActPath = ActiveDocument.Path
    While xFileStr <> ""
        xFilePath = xFolder & "\" & xFileStr
        If xFilePath <> xActPath Then
            Set xDoc = Documents.Open(xFilePath, AddToRecentFiles:=False, Visible:=False)
            xIndex = InStrRev(xFilePath, ".")
            xDoc.SaveAs Left(xFilePath, xIndex - 1) & ".txt", FileFormat:=wdFormatText, AddToRecentFiles:=False, Encoding:=msoEncodingUTF8
            xDoc.Close True
        End If
        xFileStr = Dir()
    Wend
    Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Merci beaucoup ! La conversion se fait très bien
This comment was minimized by the moderator on the site
Many thanks
This comment was minimized by the moderator on the site
Hello, Thank you for this post. When I hit "run", I get an error message:"Compile Error: Invalid Outside Procedure." This is whether I use the doc or the docx extension (maybe unrelated but I tried both.) Please can you help? I have no idea how to use code.... and really need to convert a ton of docs. Thank you!
This comment was minimized by the moderator on the site
Hi Durga,
The code works well in my case.
Please make sure that the Module (Code) window contains only the VBA code provided in the post.
This comment was minimized by the moderator on the site
That worked a treat! Thanks!
Rated 5 out of 5
This comment was minimized by the moderator on the site
I NEED them to convert to delimited text files is this possible still.
This comment was minimized by the moderator on the site
I used the script above to batch convert documents in Korean, but the script did not work. When I tired to change the encoding, Can anyone help me with this error?
This comment was minimized by the moderator on the site
Thanks for this - I was just going to code something myself when I thought, "Hey perhaps someone has done this already?" You had, and a deal more elegantly than I would have done. Thanks you for your hard work.
This comment was minimized by the moderator on the site
The script works great for me, but only for one folder. Is there any way to include all subfolders?
This comment was minimized by the moderator on the site
Thank you a lot! Worked like a charm!
This comment was minimized by the moderator on the site
Worked rapidly and perfectly on a folder full of .docx files. I thank you/
This comment was minimized by the moderator on the site
Hi, the code works but at the end gives me 'Runtime error 91', some of my files have objects. Any idea how can I fix this?
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