이 기사에서는 Word에서 특정 텍스트가 포함 된 문장을 빠르게 찾거나 삭제하는 두 가지 방법을 제공합니다.
Word에서 "찾기 및 바꾸기"기능을 사용하여 특정 단어의 모든 항목을 쉽게 찾을 수 있다는 것은 누구나 알고 있습니다. 그러면 강조 표시, 교체 또는 제거에 문제가 없습니다. 보시다시피 target은 단어 또는 구입니다. 그러나 오늘은 특정 텍스트가 포함 된 문장을 찾거나 삭제하는 매크로 방법을 알려 드리게되어 기쁩니다.
방법 1 : 특정 텍스트가 포함 된 문장 찾기 또는 삭제
- 먼저 "Alt + F11"을 눌러 Word에서 VBA 편집기를 실행합니다.
- 다음으로 "Normal"을 클릭하여 새 모듈을 만듭니다.
- 그런 다음 "삽입"을 클릭하고 "모듈"을 선택하여 새 것을 얻습니다.
- 그리고 더블 클릭으로 모듈을 엽니 다.
- 이제 다음 코드를 붙여 넣으십시오.
Sub DeleteSentencesContainingSpecificWords()
Dim strTexts As String
Dim strButtonValue As String
strTexts = InputBox("Enter texts to be found here: ")
With Selection
.HomeKey Unit:=wdStory
' Find the entered texts.
With Selection.Find
.ClearFormatting
.Text = strTexts
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
Do While .Find.Found = True
' Expand the selection to the entire sentence.
Selection.Expand Unit:=wdSentence
strButtonValue = MsgBox("Are you sure to delete the sentence?", vbYesNo)
If strButtonValue = vbYes Then
Selection.Delete
End If
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
End Sub
- 다음으로“실행”을 클릭하십시오.
- 텍스트를 입력하라는 입력 상자가 나타납니다. 모든 문장에 포함 된 공통 텍스트를 입력하기 만하면됩니다. “확인”을 클릭합니다.
- 그러면 선택한 텍스트가 포함 된 문장과 메시지 상자가 표시됩니다. 문장을 삭제하려면 "예"를 클릭하고 유지하려면 "아니오"를 클릭하십시오.
- 확인 후 지정된 텍스트가있는 다음 문장이 선택됩니다. 그리고 확인 상자도 있습니다. 즉, 매크로는 전체 문서를 단계별로 살펴보고 tar문장을 받고 매번 확인을 요청하십시오.
방법 2 : 목록에있는 모든 텍스트가 포함 된 문장 찾기 또는 삭제
방법 1의 매크로를 사용하면 한 번에 하나의 단어 또는 구문 만 검색 할 수 있습니다. 물론, 매크로를 반복적으로 실행하여 단어 나 구의 여러 인스턴스를 검색 할 수 있습니다. 다중 검색의 필요성을 충족하기 위해 다른 매크로를 제공합니다.
- 먼저 모두 넣어 tar새 문서에 대한 텍스트를 얻습니다. 각 텍스트가 후행 공백없이 한 단락을 차지하는지 확인하십시오. 문서를 닫고 저장하십시오.
- 다음으로 방법 1의 정확한 단계를 사용하여 매크로를 설치하고 실행합니다.
- 그런 다음 매크로를 다음으로 바꿉니다.
Sub DeleteSentencesContainingSpecificWordsOnAList()
Dim objListDoc As Document, objTargetDoc As Document
Dim objParaRange As Range
Dim objParagraph As Paragraph
Dim strFileName As String, strButtonValue As String
Dim dlgFile As FileDialog
Set dlgFile = Application.FileDialog(msoFileDialogFilePicker)
With dlgFile
If .Show = -1 Then
strFileName = .SelectedItems(1)
Else
MsgBox "No file is selected! Please select the target file."
Exit Sub
End If
End With
Set objTargetDoc = ActiveDocument
Set objListDoc = Documents.Open(strFileName)
objTargetDoc.Activate
For Each objParagraph In objListDoc.Paragraphs
Set objParaRange = objParagraph.Range
objParaRange.End = objParaRange.End - 1
With Selection
.HomeKey Unit:=wdStory
' Find target words.
With Selection.Find
.ClearFormatting
.Text = objParaRange
.MatchWholeWord = True
.MatchCase = False
.Execute
End With
' Expand the selection to the entire sentence.
Do While .Find.Found
Selection.Expand Unit:=wdSentence
strButtonValue = MsgBox("Are you sure to delete the sentence?", vbYesNo)
If strButtonValue = vbYes Then
Selection.Delete
End If
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
Next objParagraph
End Sub
- 이제 "찾아보기"창이 열립니다. 방금 저장 한 문서를 선택하고 "열기"를 클릭합니다.
- 다음 절차는 방법 1과 동일합니다.
손상된 문서를 처리하기위한 접근 방식
귀중한 데이터의 손실은 절대적으로 치명적입니다. 비즈니스를 위태롭게 할 수도 있습니다. 이러한 좌절을 피하기 위해 당신은 단어 수정 도구를 가능한 한 빨리. 이러한 도구는 문서 손상과의 전투에서 승리하는 데 도움이됩니다.
저자 소개 :
Vera Chen은 데이터 복구 전문가입니다. DataNumen, Inc.는 다음과 같은 데이터 복구 기술 분야의 세계적 리더입니다. Excel 수정 pdf 수리 소프트웨어 제품. 자세한 내용은 WWW.datanumen.COM



