Petua: Bahasa lain diterjemahkan Google. Anda boleh melawat English versi pautan ini.
Log masuk
x
or
x
x
Daftar Sekarang
x

or

Bagaimana untuk mencari dan menggantikan merangkumi pelbagai fail dalam perkataan?

Jika anda mempunyai beberapa dozen fail perkataan yang mengandungi kandungan yang sama (seperti Header, footer, beberapa kata atau nombor khas), dan anda perlu menggantikan kandungan yang sama merentasi dokumen tersebut dalam Word. Bagaimana lebih mudah bagi anda untuk melakukannya dengan cepat? Sudah tentu, anda boleh membuka fail-fail tersebut satu demi satu untuk menggantikan kandungan yang sama, tetapi ia akan memakan masa dan menyusahkan. Tutorial ini akan menunjukkan kepada anda cara yang rumit untuk menggantikan kandungan yang sama dalam berbilang dokumen dalam Word sekaligus.

Cari dan gantikan teks merentasi pelbagai perkataan perkataan pada masa yang sama dengan kod VBA


Menggabungkan / menggabungkan beberapa dokumen menjadi mudah:

Sistem yang Menggabungkan Dokumen utiliti Kutools untuk Word boleh membantu anda menggabungkan banyak dokumen menjadi satu dengan cepat. Anda hanya perlu:

  • Pilih dokumen yang akan anda gabungkan;
  • Tentukan rehat antara setiap dokumen gabungan;
  • Mula menggabungkan. Lihat tangkapan skrin:

Kutools untuk Word: dengan lebih daripada 100 Word add-in berguna, bebas untuk mencuba tanpa had pada hari 30. Muat turun dan percubaan percuma Sekarang!

Kutools untuk Word: Tambah 100 Ciri-ciri Lanjutan Baru kepada Word 2003 / 2007 / 2010 / 2013 / 2016 / 2019.
Tab Pejabat: Dayakan Penyuntingan dan Penyemakan Tab di Pejabat, Sama seperti Chrome, Firefox, IE 8 / 9 / 10.
Menu Klasik untuk Pejabat: Bawa Pandang Lama Pejabat 2003 Kembali ke Office 2007, 2010, 2013, 2016 dan 2019.

Cari dan gantikan teks merentasi pelbagai perkataan perkataan pada masa yang sama dengan kod VBA

1. Akhbar Alt + F11 untuk membuka Microsoft Visual Basic untuk Aplikasi tingkap.

2. Di dalam Microsoft Visual Basic untuk Aplikasi tetingkap, klik Memasukkan > Modul, kemudian salin kod VBA berikut ke dalam tetingkap Modul.

Kod VBA: Mencari dan menggantikan kandungan yang sama merentas berbilang dokumen pada satu masa

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. Tekan butang F5 kunci untuk menjalankan kod.

4. Dalam pembukaan Semak imbas tetingkap, sila cari dan pilih dokumen yang akan anda temukan dan ganti teks di dalam, dan kemudian klik OK butang. Lihat tangkapan skrin:

5. Yang pertama Kutools untuk Word kotak dialog, masukkan teks yang anda akan temui merentas dokumen ke dalam Cari apa kotak, dan kemudian klik OK butang.

6. Pada yang kedua Kutools untuk Word kotak dialog, masukkan teks yang akan digantikan dengan, dan klik OK butang.

8. Klik OK butang di sebelah Microsoft word kotak dialog untuk menyelesaikan mencari dan menggantikannya.

Dalam kes ini, semua perkataan "Word" dalam dokumen terpilih digantikan dengan "Excel" pada masa yang sama.


Tab Pejabat - Pelayaran Tab, Penyuntingan, dan Urusan beberapa Dokumen di Word:

Tab Office membawa antara muka tab seperti yang dilihat dalam pelayar web seperti Google Chrome, versi baru Internet Explorer dan Firefox ke Microsoft Word. Ia akan menjadi alat penjimatan masa dan tidak mereput semula dalam kerja anda. Lihat demo di bawah:

Klik untuk percubaan percuma Tab Pejabat!




Kutools untuk Word

Lebih daripada Fungsi Lanjutan 100 untuk Word 2003, 2007, 2010, 2013, 2016 dan 2019

shot-kutools-700-225-kte

Lebih Ciri-ciri | Muat turun percuma | Hanya $ 39.00 untuk beratus-ratus fungsi

Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Tiago · 26 days ago
    Is it possible to replace in the headers of the word doc?
    • To post as a guest, your comment is unpublished.
      crystal · 22 days ago
      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
  • To post as a guest, your comment is unpublished.
    dsadasd · 26 days ago
    Is that possible to replace in the header of the word doc?
  • To post as a guest, your comment is unpublished.
    martinadam · 3 months ago
    Thanks for sharing this information with us.
    Word search and replace tool
  • To post as a guest, your comment is unpublished.
    nathalie · 5 months ago
    Works perfectly but is there a similar macro to change text in the header! because this does not work with this version!
    thanks
    • To post as a guest, your comment is unpublished.
      crystal · 22 days ago
      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
  • To post as a guest, your comment is unpublished.
    blds · 1 years ago
    Doesn't work for me on footers. e.g find FFSOSxxxx and replace with GGSOSxxxx, i can see this code is great for others pls help. :(