メインコンテンツへスキップ

Wordで複数のファイルを検索して置き換える方法は?

同じコンテンツ(ヘッダー、フッター、いくつかの特別な単語や数字など)を含む数十の単語ファイルがあり、Word内のそれらのドキュメント全体で同じコンテンツを置き換える必要がある場合。 あなたがそれを素早く成し遂げるのはどのように簡単でしょうか? 確かに、それらのファイルをXNUMXつずつ開いて同じコンテンツを置き換えることはできますが、時間と手間がかかります。 このチュートリアルでは、Wordの複数のドキュメント内の同じコンテンツを一度に置き換えるトリッキーな方法を紹介します。

複数のWord文書にまたがるテキストを同時に検索し、VBAコードで置き換えます
Kutools for Wordを使用すると、複数のドキュメントにまたがるさまざまなテキストを同時に簡単に見つけて置き換えることができます。


複数のWord文書にまたがるテキストを同時に検索し、VBAコードで置き換えます

1。 押す 他の + F11 を開く アプリケーション向け Microsoft Visual Basic 窓。

2。 の中に アプリケーション向け Microsoft Visual Basic ウィンドウ、クリック インセットモジュール、次に、次のVBAコードをモジュールウィンドウにコピーします。

VBAコード:一度に複数のドキュメントで同じコンテンツを検索して置き換える

Sub CommandButton1_Click()
'Updated by Extendoffice 20180625
Dim xFileDialog As FileDialog, GetStr(1 To 100) As String '100 files is the maximum applying this code
Dim xFindStr As String
Dim xReplaceStr As String
Dim xDoc As Document
On Error Resume Next
Set xFileDialog = Application.FileDialog(msoFileDialogFilePicker)
With xFileDialog
    .Filters.Clear
    .Filters.Add "All WORD File ", "*.docx", 1
    .AllowMultiSelect = True
    i = 1
    If .Show = -1 Then
        For Each stiSelectedItem In .SelectedItems
            GetStr(i) = stiSelectedItem
            i = i + 1
        Next
        i = i - 1
    End If
    Application.ScreenUpdating = False
    xFindStr = InputBox("Find what:", "Kutools for Word", xFindStr)
    xReplaceStr = InputBox("Replace with:", "Kutools for Word", xReplaceStr)
    For j = 1 To i Step 1
        Set xDoc = Documents.Open(FileName:=GetStr(j), Visible:=True)
        Windows(GetStr(j)).Activate
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = xFindStr  'Find What
            .Replacement.Text = xReplaceStr  'Replace With
            .Forward = True
            .Wrap = wdFindAsk
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
        Application.Run macroname:="NEWMACROS"
        ActiveDocument.Save
        ActiveWindow.Close
    Next
    Application.ScreenUpdating = True
End With
MsgBox "Operation end, please view", vbInformation
End Sub

3。 プレス F5 コードを実行するためのキー。

4.オープニングで ブラウズ ウィンドウで、検索するドキュメントを見つけて選択し、内部のテキストを置き換えてから、[ OK ボタン。 スクリーンショットを参照してください:

5.最初に Kutools for Word ダイアログボックスで、ドキュメント全体に表示されるテキストを 見つける ボックスをクリックし、 OK

6番目に Kutools for Word ダイアログボックスで、置き換えるテキストを入力し、[ OK

8。 クリック OK 次のボタン マイクロソフトワード 検索と置換を終了するダイアログボックス。

この場合、選択したドキュメント内のすべての単語「Word」が同時に「Excel」に置き換えられます。


Kutools for Wordを使用すると、複数のドキュメントにまたがるさまざまなテキストを同時に簡単に見つけて置き換えることができます。

ここで強くお勧めします バッチ検索と置換 の特徴 Kutools for Word。 この機能を使用すると、複数のWord文書で異なるテキストを同時に簡単に見つけて置き換えることができます。 この機能を適用して、ドキュメント全体のテキストを検索して置換する方法を見てみましょう。

Kutools for Word :100以上の便利なWordアドインで、 制限なしで無料で試すことができます 60 日々.

1.をクリックしてください クツールズプラス > バッチ検索と置換 この機能を有効にします。

2。 の中に バッチ検索と置換 ダイアログボックスで、次のように構成してください。

  • 2.1)をクリックします 行を追加 ボタンの下に 検索および置換 タブ;
  • 2.2)作成された行フィールド:
A.見つけたテキストをのテキストボックスに入力してください もう完成させ、ワークスペースに掲示しましたか? の項目に表示されます。
B.置換するテキストをのテキストボックスに入力します 交換する カラム;
C.必要に応じて、テキストを検索する場所とテキストを強調表示する色を指定します。 この場合、私は選択します フルワードマッチング, メインドキュメント とからの特定の色 検索タイプ、 で見つける & 特徴 列;
  • 2.3)ステップ2.1と2.2を繰り返して、見つけて置き換えるテキストをさらに追加します。
  • 2.4)をクリックします  ボタンの ファイルの種類 テキストを見つけて置き換えるWord文書を追加するセクション。
  • 2.5)をクリックします 交換する or もう完成させ、ワークスペースに掲示しましたか? ボタン。 スクリーンショットを参照してください:

ノート:
1.をクリックした場合 もう完成させ、ワークスペースに掲示しましたか? ボタンをクリックすると、すべての検索結果が下に表示されます。 プレビュー結果 タブ。 結果をプレビューした後、すべてのテキストを置き換える場合は、をクリックしてください。 検索および置換 タブ。 それ以外の場合は、ダイアログを閉じます。

2.をクリックした場合 交換する ボタンをクリックすると、指定したすべてのテキストがすぐに新しいテキストに置き換えられ、結果も下に表示されます。 プレビュー結果 タブには何も表示されないことに注意してください。

3.手順2で強調表示の色を指定すると、置き換えられたすべてのテキストが指定された色で強調表示され、ドキュメントで一目で簡単に見つけることができます。

3。 それを閉めて バッチ検索と置換 ダイアログボックス

この機能の詳細については、 ここをクリック....

このユーティリティの無料トライアルをご希望の場合は、 ソフトウェアを無料でダウンロード まず、上記の手順に従って操作を適用します。

最高のオフィス生産性向上ツール

Kutools for Word - Over で単語体験を向上させましょう 100 注目すべき機能!

🤖 Kutools AI アシスタント: AI であなたの文章を変革します - コンテンツを生成する  /  テキストを書き換える  /  文書を要約する  /  情報のお問い合わせ 文書に基づいて、すべて Word 内で

📘 ドキュメントマスタリー: 分割ページ  /  ドキュメントをマージする  /  選択内容をさまざまな形式でエクスポート (PDF/TXT/DOC/HTML...)  /  PDFへの一括変換  /  ページを画像としてエクスポート  /  複数のファイルを一度に印刷する...

コンテンツ編集: バッチ検索と置換 複数のファイルにわたる  /  すべての画像のサイズを変更する  /  テーブルの行と列を転置する  /  表をテキストに変換...

🧹 楽にお掃除:振り払って 余分なスペース  /  セクションブレーク  /  すべてのヘッダー  /  テキストボックス  /  ハイパーリンク  / その​​他の取り外しツールについては、当社の Web サイトをご覧ください。 グループを削除...

クリエイティブインサート:挿入 千の区切り文字  /  チェックボックス  /  ラジオボタン  /  QRコード  /  バーコード  /  斜線テーブル  /  方程式のキャプション  /  画像キャプション  /  テーブルキャプション  /  複数の写真  / 詳細については、 グループを挿入...

🔍 正確な選択: ピンポイント 特定のページ  /  テーブル  /  シェイプ  /  見出し段落  / ナビゲーションを強化する 他には? 機能の選択...

スターの強化: あらゆる場所に素早く移動  /  繰り返しのテキストを自動挿入  /  ドキュメントウィンドウをシームレスに切り替える  /  11 変換ツール...

👉 これらの機能を試してみませんか? Kutools for Wordは、 60日無料トライアル、制限なし! 🚀
 
Comments (70)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
thanks for -How To Search And Replace Across Multiple Files In Word?

what about from out side (by folder) ?

thanks gain
This comment was minimized by the moderator on the site
This is a great explanation.  Is there a way to change settings, e.g. page size, simultaneously? 
This comment was minimized by the moderator on the site
After pressing F5, I get the following error" "Compile error: User-defined type not defined." Can someone help?
This comment was minimized by the moderator on the site
Hi Monique,Please check if the Microsoft Office Object Library is enabled as shown in the screenshot below.
This comment was minimized by the moderator on the site
This is SUCH a time saving solution. THANK YOU!
One thing that may make it even better, is adding support for subdirectories. (That is: Files in multiple subdirectories)
I am an absolute newbie in this, and don't know the syntax, the parameter, or where to add that.

Could somebody help?
This comment was minimized by the moderator on the site
I need to replace text in multiple Word files and have the replaced text highlighted. Is there a way to do this?
This comment was minimized by the moderator on the site
Hi Daphne,
Why not try the Batch Find and Replace feature of Kutools for Word? It can solve this issue with ease.
This comment was minimized by the moderator on the site
this was a lifesaver thank you so much
This comment was minimized by the moderator on the site
Is it possible to replace in the headers of the word doc?
This comment was minimized by the moderator on the site
Hi Tiago,
Please apply the below VBA code to include the content of headers and footers when finding and replacing texts in multiple documents at once.

Sub CommandButton1_Click()
'Updated by Extendoffice 20180625
Dim xFileDialog As FileDialog, GetStr(1 To 100) As String '100 files is the maximum applying this code
Dim xFindStr As String
Dim xReplaceStr As String
Dim xDoc As Document
On Error Resume Next
Set xFileDialog = Application.FileDialog(msoFileDialogFilePicker)
With xFileDialog
.Filters.Clear
.Filters.Add "All WORD File ", "*.docx", 1
.AllowMultiSelect = True
i = 1
If .Show = -1 Then
For Each stiSelectedItem In .SelectedItems
GetStr(i) = stiSelectedItem
i = i + 1
Next
i = i - 1
End If
Application.ScreenUpdating = False
xFindStr = InputBox("Find what:", "Kutools for Word", xFindStr)
xReplaceStr = InputBox("Replace with:", "Kutools for Word", xReplaceStr)
For j = 1 To i Step 1
Set xDoc = Documents.Open(FileName:=GetStr(j), Visible:=True)
Windows(GetStr(j)).Activate
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = xFindStr 'Find What
.Replacement.Text = xReplaceStr 'Replace With
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Application.Run macroname:="NEWMACROS"
If MsgBox("Do you want to replace texts in headers and footers too? ", vbYesNo, "Kutools for Word") = vbYes Then
ActiveWindow.View.SplitSpecial = wdPanePrimaryFooter
Selection.Find.Execute Replace:=wdReplaceAll
Application.Run macroname:="NEWMACROS"
ActiveWindow.View.SplitSpecial = wdPanePrimaryHeader
Selection.Find.Execute Replace:=wdReplaceAll
Application.Run macroname:="NEWMACROS"
End If
ActiveDocument.Save
ActiveWindow.Close
Next
Application.ScreenUpdating = True
End With
MsgBox "Operation end, please view", vbInformation
End Sub
This comment was minimized by the moderator on the site
Is that possible to replace in the header of the word doc?
This comment was minimized by the moderator on the site
Thanks for sharing this information with us.
Word search and replace tool
This comment was minimized by the moderator on the site
Works perfectly but is there a similar macro to change text in the header! because this does not work with this version!
thanks
This comment was minimized by the moderator on the site
Hi,
Please apply the below VBA code to include the content of headers and footers when finding and replacing texts in multiple documents at once.

Sub CommandButton1_Click()
'Updated by Extendoffice 20180625
Dim xFileDialog As FileDialog, GetStr(1 To 100) As String '100 files is the maximum applying this code
Dim xFindStr As String
Dim xReplaceStr As String
Dim xDoc As Document
On Error Resume Next
Set xFileDialog = Application.FileDialog(msoFileDialogFilePicker)
With xFileDialog
.Filters.Clear
.Filters.Add "All WORD File ", "*.docx", 1
.AllowMultiSelect = True
i = 1
If .Show = -1 Then
For Each stiSelectedItem In .SelectedItems
GetStr(i) = stiSelectedItem
i = i + 1
Next
i = i - 1
End If
Application.ScreenUpdating = False
xFindStr = InputBox("Find what:", "Kutools for Word", xFindStr)
xReplaceStr = InputBox("Replace with:", "Kutools for Word", xReplaceStr)
For j = 1 To i Step 1
Set xDoc = Documents.Open(FileName:=GetStr(j), Visible:=True)
Windows(GetStr(j)).Activate
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = xFindStr 'Find What
.Replacement.Text = xReplaceStr 'Replace With
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Application.Run macroname:="NEWMACROS"
If MsgBox("Do you want to replace texts in headers and footers too? ", vbYesNo, "Kutools for Word") = vbYes Then
ActiveWindow.View.SplitSpecial = wdPanePrimaryFooter
Selection.Find.Execute Replace:=wdReplaceAll
Application.Run macroname:="NEWMACROS"
ActiveWindow.View.SplitSpecial = wdPanePrimaryHeader
Selection.Find.Execute Replace:=wdReplaceAll
Application.Run macroname:="NEWMACROS"
End If
ActiveDocument.Save
ActiveWindow.Close
Next
Application.ScreenUpdating = True
End With
MsgBox "Operation end, please view", vbInformation
End Sub
This comment was minimized by the moderator on the site
Oh yeah! Thank you sooooo much! This is a life-saver!
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