메인 컨텐츠로 가기

Excel에서 Word 문서의 텍스트를 찾고 바꾸는 방법은 무엇입니까?

Word 문서에서 찾기 및 바꾸기 기능을 적용하여 하나의 텍스트를 빠르게 찾고 바꿀 수 있습니다. 그러나 찾아서 바꿔야 하는 텍스트가 여러 개인 경우 찾기 및 바꾸기 기능에 텍스트를 하나씩 입력하는 데 시간이 많이 걸립니다. 이 경우 찾기 및 바꾸기 텍스트를 셀 목록에 입력하고 Excel의 VBA 코드를 사용하여 이 작업을 쉽게 수행할 수 있습니다. 이 기사에서는 여러 Word 문서에서 텍스트를 일괄 검색하고 바꾸는 유용한 기능도 소개합니다.

Excel에서 VBA 코드로 하나의 Word 문서에서 여러 텍스트 찾기 및 바꾸기

Excel의 여러 Word 문서에서 여러 텍스트를 찾아 VBA 코드로 바꾸기

강력한 기능으로 여러 Word 문서에서 여러 텍스트 찾기 및 바꾸기


Excel에서 VBA 코드로 하나의 Word 문서에서 여러 텍스트 찾기 및 바꾸기

하나의 Word 파일에서만 일부 텍스트를 찾아서 바꾸려는 경우 다음 VBA 코드가 도움이 될 수 있습니다.

1. Excel 워크시트에서 아래 스크린샷과 같이 찾고 바꿀 텍스트가 포함된 열과 바꿀 텍스트가 있는 다른 열을 만듭니다. 그런 다음 Alt + F11 동시에 열려면 키 응용 프로그램 용 Microsoft Visual Basic 창.

2. 그런 다음 끼워 넣다 > 모듈, 아래 VBA 코드를 복사하여 창에 붙여넣습니다.

VBA 코드: 하나의 Word 파일에서 여러 텍스트 찾기 및 바꾸기

Sub replace_texts_range_of_cells()
'Updateby ExtendOffice
Dim xWordApp As Word.Application
Dim xDoc As Word.Document
Dim xRng As Range
Dim I As Integer
Dim xFileDlg As FileDialog
On Error GoTo ExitSub
Set xFileDlg = Application.FileDialog(msoFileDialogFilePicker)
xFileDlg.AllowMultiSelect = False
xFileDlg.Filters.Add "Word Document", "*.docx; *.doc; *.docm"
xFileDlg.FilterIndex = 2
If xFileDlg.Show <> -1 Then GoTo ExitSub
Set xRng = Application.InputBox("Please select the lists of find and replace texts (Press Ctrl key to select two same size ranges):", "Kutools for Excel", , , , , , 8)
If xRng.Areas.Count <> 2 Then
  MsgBox "Please select two columns (press Ctrl key), the two ranges have the same size.", vbInformation + vbOKOnly, "Kutools for Excel"
  GoTo ExitSub
End If
If (xRng.Areas.Item(1).Rows.Count <> xRng.Areas.Item(2).Rows.Count) Or _
  (xRng.Areas.Item(1).Columns.Count <> xRng.Areas.Item(2).Columns.Count) Then
  MsgBox "Please select two columns (press Ctrl key), the two ranges have the same size.", vbInformation + vbOKOnly, "Kutools for Excel"
  GoTo ExitSub
End If
Set xWordApp = CreateObject("Word.application")
xWordApp.Visible = True
Set xDoc = xWordApp.Documents.Open(xFileDlg.SelectedItems.Item(1))
For I = 1 To xRng.Areas.Item(1).Cells.Count
  With xDoc.Application.Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = xRng.Areas.Item(1).Cells.Item(I).Value
    .Replacement.Text = xRng.Areas.Item(2).Cells.Item(I).Value
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchByte = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
  End With
  xDoc.Application.Selection.Find.Execute Replace:=wdReplaceAll
Next
ExitSub:
  Set xRng = Nothing
  Set xFileDlg = Nothing
  Set xWordApp = Nothing
  Set xDoc = Nothing
End Sub

3. 코드를 붙여넣은 후에도 여전히 응용 프로그램 용 Microsoft Visual Basic 창을 클릭합니다 도구 > 참고자료, 스크린 샷 참조 :

4. 튀어 나온 참조 – VBAProject 대화 상자에서 Microsoft Word 16.0 개체 라이브러리 목록 상자에서 스크린샷 참조:

5. 딸깍 하는 소리 OK 버튼을 눌러 대화 상자를 닫고 이제 F5 이 코드를 실행하려면 팝업 찾아보기 창에서 텍스트를 대체할 Word 파일을 선택하고 스크린샷을 참조하십시오.

6. 그런 다음 OK, 다음 대화 상자에서 Ctrl 키 키를 사용하여 사용하려는 원본 텍스트와 새 텍스트 셀을 별도로 선택하려면 스크린샷을 참조하십시오.

7. 그런 다음 OK 버튼을 누르면 지정된 문서에서 텍스트를 찾아 새 텍스트로 대체하고 파일도 열리므로 변경 사항을 유지하려면 저장해야 합니다.


Excel의 여러 Word 문서에서 여러 텍스트를 찾아 VBA 코드로 바꾸기

여기에서 여러 Word 문서에서 여러 텍스트를 찾고 바꾸기 위한 VBA 코드도 만듭니다. 다음과 같이 하십시오.

1. 아래 스크린샷과 같이 교체 및 교체할 값의 두 열이 포함된 Excel 파일을 연 다음 키를 누릅니다. Alt + F11 동시에 열려면 키 응용 프로그램 용 Microsoft Visual Basic 창.

2. 그런 다음 끼워 넣다 > 모듈, 아래 VBA 코드를 복사하여 창에 붙여넣습니다.

VBA 코드: 여러 Word 파일에서 여러 텍스트 찾기 및 바꾸기

Sub FindReplaceAcrossMultipleWordDocuments()
'Updateby ExtendOffice
Dim xWordApp As Word.Application
Dim xDoc As Word.Document
Dim xRng As Range
Dim I As Integer
Dim xFolderDlg As FileDialog
Dim xFSO As Scripting.FileSystemObject
Dim xFile As File
On Error GoTo ExitSub
Set xFolderDlg = Application.FileDialog(msoFileDialogFolderPicker)
If xFolderDlg.Show <> -1 Then GoTo ExitSub
Set xRng = Application.InputBox("Please select the lists of find and replace texts (Press Ctrl key to select two same size ranges", "Kutools for Excel", , , , , , 8)
If xRng.Areas.Count <> 2 Then
  MsgBox "Please select two columns (press Ctrl key), the two ranges have the same size", vbInformation + vbOKOnly, "Kutools for Excel"
  GoTo ExitSub
End If
If (xRng.Areas.Item(1).Rows.Count <> xRng.Areas.Item(2).Rows.Count) Or _
  (xRng.Areas.Item(1).Columns.Count <> xRng.Areas.Item(2).Columns.Count) Then
  MsgBox "Please select two columns (press Ctrl key), the two ranges have the same size.", vbInformation + vbOKOnly, "Kutools for Excel"
  GoTo ExitSub
End If
Set xFSO = New Scripting.FileSystemObject
Set xWordApp = CreateObject("Word.application")
xWordApp.Visible = True
For Each xFile In xFSO.GetFolder(xFolderDlg.SelectedItems(1)).Files
  If VBA.InStr(xFile.Type, "Microsoft Word") > 0 Then
    Set xDoc = xWordApp.Documents.Open(xFile.Path)
    For I = 1 To xRng.Areas.Item(1).Cells.Count
      With xDoc.Application.Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = xRng.Areas.Item(1).Cells.Item(I).Value
        .Replacement.Text = xRng.Areas.Item(2).Cells.Item(I).Value
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
      End With
      xDoc.Application.Selection.Find.Execute Replace:=wdReplaceAll
    Next
    xDoc.Close wdSaveChanges
  End If
Next
xWordApp.Quit
MsgBox "The Find and Replace has been completed", vbInformation + vbOKOnly, "Kutools for Excel"
ExitSub:
  Set xRng = Nothing
  Set xFolderDlg = Nothing
  Set xWordApp = Nothing
  Set xDoc = Nothing
End Sub

3. 여전히 응용 프로그램 용 Microsoft Visual Basic 창을 클릭합니다 도구 > 참고자료,에 참조 – VBAProject 대화 상자에서 Microsoft Word 16.0 개체 라이브러리Microsoft 스크립팅 런타임 목록 상자에서 옵션, 스크린샷 참조:

4. 두 가지 옵션을 확인한 후 다음을 클릭합니다. OK 대화 상자를 닫고 계속 F5 오프닝에서 이 코드를 실행하기 위한 키 검색 창에서 찾기 및 바꾸기를 수행하려는 Word 문서가 포함된 폴더를 선택합니다. 스크린샷을 참조하십시오.

5. 딸깍 하는 소리 OK 버튼, 팝업 대화 상자에서 Ctrl 키 키를 사용하여 사용하려는 원본 텍스트와 새 텍스트 열을 별도로 선택하려면 스크린샷을 참조하십시오.

6. 마지막으로 OK, 원본 텍스트는 이 파일에서 새 텍스트로 대체됩니다. 완료되면 아래 스크린샷과 같이 대화 상자가 나타납니다.

7. 딸깍 하는 소리 OK 대화 상자를 닫습니다. 그리고 파일로 이동하여 변환된 결과를 확인할 수 있습니다.


강력한 기능으로 여러 Word 문서에서 여러 텍스트 찾기 및 바꾸기

이 섹션에서는 Excel 대신 Word에서 여러 Word 문서의 텍스트를 일괄 검색하고 바꾸는 방법에 대해 설명합니다. 강력한 도구로-Word 용 Kutools, 특정 텍스트를 빠르게 찾아 교체하고 기본 파일, 머리글, 바닥글, 주석 등의 새 텍스트로 교체하고 필요에 따라 결과를 강조 표시할 수 있습니다.

1. 하나의 Word 파일을 연 다음 쿠툴즈 플러스 > 일괄 찾기 및 바꾸기, 스크린 샷 참조 :

2. 열린 일괄 찾기 및 바꾸기 대화 상자에서 다음 작업을 수행하십시오.

  • 추가 텍스트를 찾고 바꿀 Word 파일을 추가하는 버튼;
  • 왼쪽 창에서 행 추가 상단 리본에서;
  • 삽입된 필드에 원본 텍스트와 새 텍스트를 입력합니다. Find교체 찾아서 바꾸려는 열을 별도로 선택합니다. 또한 필요에 따라 교체된 텍스트를 강조 표시하는 색상을 지정할 수 있습니다.

3. 검색 기준을 만든 후 교체 버튼으로 이동 미리보기 결과 탭을 클릭하여 찾기 및 바꾸기 결과를 봅니다. 스크린샷 참조:

4. 그런 다음 닫기 버튼을 누르면 이 시나리오를 저장할 것인지 알려주는 프롬프트 상자가 나타납니다. 가능 저장하고 아니 무시하려면 스크린 샷을 참조하십시오.

방문 꿀팁: 이 기능은 다음 작업을 수행하는 데도 도움이 될 수 있습니다.
  • 여러 Word 문서에서 특수 문자 찾기 및 바꾸기
  • 여러 Word 문서에서 여러 문자열을 찾아 특정 서식으로 바꿉니다.
  • 여러 txt/htm/html 파일에서 여러 문자열을 찾아서 바꿉니다.

이 기능에 대한 자세한 정보를 보려면 클릭하십시오…

최고의 사무 생산성 도구

🤖 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 (10)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
This works great, thank you! Is there a way to make the replacement text carry hyperlinks over? ie - if you have a hyperlinked replacement in the excel sheet, it is still hyperlinked in the Word doc?

Thanks!
This comment was minimized by the moderator on the site
Is there a way too modify this too find text and create hyperlink on the text from another column where i have the links already created? It worked correctly as a find and replace for me. Thanks
This comment was minimized by the moderator on the site
Hi,

I am wondering how this can be modified to also find and replace text in footnotes?

Thanks!
This comment was minimized by the moderator on the site
Hello, Nate,
If you want to find and replace the text in footnotes at the same time, maybe the Kutools for Word's Batch Find and Replace feature can help you.
You just need to check Main document and Footnotes from the Find in section, see below image:
https://www.extendoffice.com/images/stories/comments/comment-skyyang/2023-comment/doc-find-replace-word.png
This comment was minimized by the moderator on the site
It doesn't work.

Compile error: User-defined type not defined
This comment was minimized by the moderator on the site
Hello, Param
The code works well.
Maybe, you didn't check Microsoft Word 16.0 Object Library from the References – VBAProject dialog box.
It means that you may miss the Step 3 and Step 4 of this article.
Please try again, if you still have any other problem, please comment here.
https://www.extendoffice.com/images/stories/comments/comment-skyyang/2023-comment/doc-find-replace-word-file-excel.png
This comment was minimized by the moderator on the site
Sorry for the overdue reply. I have replied before, but my reply dissapeared somehow. You're right, the code does work well. But it replaced nothing when I tried it on a file with more than 80,000 lines.
This comment was minimized by the moderator on the site
Hello, Param
I have tested the code, it works well in my Word docuent which contains 140,000 lines.
Do you mind to upload your attachment here for testing?
Or you can apply our Kutools for Word's Batch Find and Replace feature, it can help you with ease.
Thank you!
This comment was minimized by the moderator on the site
Greetings,
the first code :
VBA code: Find and replace multiple texts in one Word file

thows error : compile error user defined type not defined
https://i.imgur.com/FZPBy4I.png
This comment was minimized by the moderator on the site
Hello, Erik
The code works well.
Maybe, you didn't check Microsoft Word 16.0 Object Library from the References – VBAProject dialog box.
It means that you may miss the Step 3 and Step 4 of this article.
Please try again, if you still have any other problem, please comment here.

https://www.extendoffice.com/images/stories/comments/comment-skyyang/2023-comment/doc-find-replace-word-file-excel.png
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations