Tip: andere talen zijn Google-Vertaald. Je kunt het English versie van deze link.
Log in
x
or
x
x
Registreren
x

or

Hoe te zoeken en vervangen over meerdere bestanden in woord?

Als u enkele tientallen woordbestanden hebt die dezelfde inhoud bevatten (zoals koptekst, voettekst, een aantal speciale woorden of een nummer) en u dezelfde inhoud in die documenten in Word moet vervangen. Hoe zou het voor u gemakkelijker zijn om het snel gedaan te krijgen? Zeker, u kunt die bestanden een voor een openen om dezelfde inhoud te vervangen, maar het zal tijdrovend en lastig zijn. Deze zelfstudie toont u een lastige manier om dezelfde inhoud tegelijkertijd in meerdere documenten in Word te vervangen.

Zoek en vervang teksten in meerdere woorddocumenten tegelijk met VBA-code


Combineer / voeg meerdere documenten gemakkelijk samen tot één:

De Documenten samenvoegen nut van Kutools for Word kan u helpen om meerdere documenten snel in één te combineren. U hoeft alleen:

  • Selecteer de documenten die u wilt combineren in één;
  • Geef de pauze op tussen elk gecombineerd document;
  • Begin met samenvoegen. Zie screenshot:

Kutools for Word: met meer dan 100 handige invoegtoepassingen voor Word, gratis om zonder beperkingen in 30-dagen te proberen. Download en gratis proef nu!

Kutools for Word: Voeg 100 nieuwe geavanceerde functies toe naar Word 2003 / 2007 / 2010 / 2013 / 2016 / 2019.
Office Tab: Inschakelen Bewerken en bladeren met tabbladen in Office, Net als Chrome, Firefox, IE 8 / 9 / 10.
Classic Menu for Office: Breng Old Look van Office 2003 terug naar Office 2007, 2010, 2013, 2016 en 2019.

Zoek en vervang teksten in meerdere woorddocumenten tegelijk met VBA-code

1. druk op anders + F11 om de te openen Microsoft Visual Basic voor toepassingen venster.

2. In de Microsoft Visual Basic voor toepassingen venster klikt bijvoegsel > module, kopieer vervolgens de volgende VBA-code naar het modulevenster.

VBA-code: zoek en vervang dezelfde inhoud in meerdere documenten tegelijk

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. druk de F5 sleutel om de code uit te voeren.

4. In de opening Blader venster, zoek en selecteer de documenten die u zult vinden en vervang tekst in en klik vervolgens op de OK knop. Zie screenshot:

5. In de eerste Kutools for Word dialoogvenster, voer de tekst in die u vindt in alle documenten in de Zoeken naar in en klik op de OK knop.

6. In de seconde Kutools for Word dialoogvenster, voer de tekst in die u wilt vervangen en klik op de OK knop.

8. Klik op het OK knop in de volgende Microsoft Word dialoogvenster om het zoeken en vervangen te voltooien.

In dit geval worden alle woorden 'Word' in geselecteerde documenten op hetzelfde moment vervangen door 'Excel'.


Office Tab - Bladeren met tabbladen, bewerken en beheren van meerdere documenten in Word:

Office-tabblad brengt de interface met tabbladen zoals te zien in webbrowsers zoals Google Chrome, nieuwe versies van Internet Explorer en Firefox naar Microsoft Word. Het wil een tijdbesparend hulpmiddel zijn en onherroepelijk in je werk. Zie onderstaande demo:

Klik voor gratis proefversie van Office Tab!




Kutools for Word

Meer dan 100 geavanceerde functies voor Word 2003, 2007, 2010, 2013, 2016 en 2019

schot-kutools-700-225-kte

Meer functies | Gratis download | Alleen $ 39.00 voor honderden functies

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.
    Pia · 4 years ago
    It only runs across selected files and files must be in one folder only. This is run as a macro in a word doc. It is run from clicking a button. It only updates word doc's Hope this helps.


    Private Sub CommandButton1_Click()
    Dim MyDialog As FileDialog, GetStr(1 To 100) As String '100 files is the maximum applying this code
    On Error Resume Next
    Set MyDialog = Application.FileDialog(msoFileDialogFilePicker)
    With MyDialog
    .Filters.Clear
    '~~> Change this file extention to the relevant doc type.
    .Filters.Add "All WORD File ", "*.doc", 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
    For j = 1 To i Step 1
    Set doc = Documents.Open(FileName:=GetStr(j), Visible:=True)
    Windows(GetStr(j)).Activate
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting

    For i = 1 To doc.Hyperlinks.Count
    'If the hyperlink matches.
    If LCase(doc.Hyperlinks(i).Address) = "http://www.yahoo.co.uk/" Then
    'Change the links address.
    doc.Hyperlinks(i).Address = "https://www.google.co.uk"
    'Change the links display text if desired.
    doc.Hyperlinks(i).TextToDisplay = "www.google.co.uk"
    End If
    Next
    Application.Run macroname:="NEWMACROS"
    ActiveDocument.Save
    ActiveDocument.Close
    Next
    Application.ScreenUpdating = True
    End With
    MsgBox "operation end, please view", vbInformation
    End Sub
  • To post as a guest, your comment is unpublished.
    Pia Wilson · 4 years ago
    You then add one of the following two sections depending on if it is test or hyperlink to be replaced

    '~~> This section if uncommented will replace text - ONLY ONE OF TWO SECTIONS CAN BE UNCOMMENTED AT ONCE


    With Selection.Find
    .Text = "www.google.co.uk" 'Find What
    .Replacement.Text = "www.google.com" '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
    ActiveDocument.Close
    Next
    Application.ScreenUpdating = True
    End With
    MsgBox "operation end, please view", vbInformation


    '~~> This section if uncommented will replace hyperlinks
    'For i = 1 To doc.Hyperlinks.Count
    ' 'If the hyperlink matches.
    ' If LCase(doc.Hyperlinks(i).Address) = "http://www.google.co.uk/" Then
    ' 'Change the links address.
    ' doc.Hyperlinks(i).Address = "https://www.google.com"
    ' 'Change the links display text if desired.
    ' doc.Hyperlinks(i).TextToDisplay = "www.google.com"
    ' End If
    ' Next
    'Application.Run macroname:="NEWMACROS"
    'ActiveDocument.Save
    'ActiveDocument.Close
    'Next
    'Application.ScreenUpdating = True
    'End With
    'MsgBox "operation end, please view", vbInformation



    End Sub
    • To post as a guest, your comment is unpublished.
      segarn · 4 years ago
      Hi Pia,
      I am trying to run your script for replacing hyperlinks but am getting errors. Any chance you can post the script for replacing hyperlinks all in 1 piece? I must be messing something up when trying to patch your code together.
  • To post as a guest, your comment is unpublished.
    Pia Wilson · 4 years ago
    This is what finally worked for me. I hope it helps. I added this macro to a word file. It will run the replace any documents selected (you can select as many as you like) when the file dialoge is open. It wont work on sub folders so I did each folder in the file structure individually but it worked.It may not be the best fix but it works at least.


    Private Sub CommandButton1_Click()
    Dim MyDialog As FileDialog, GetStr(1 To 100) As String '100 files is the maximum applying this code
    On Error Resume Next
    Set MyDialog = Application.FileDialog(msoFileDialogFilePicker)
    With MyDialog
    .Filters.Clear
    '~~> Change this file extention to the relevant doc type.
    .Filters.Add "All WORD File ", "*.doc", 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
    For j = 1 To i Step 1
    Set doc = Documents.Open(FileName:=GetStr(j), Visible:=True)
    Windows(GetStr(j)).Activate
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    'Section then either one or the other of sections of code to follow.
  • To post as a guest, your comment is unpublished.
    Greg Simonis · 4 years ago
    I still cannot get this to work on my PC running Windows 7.
    When I run it, I get an error msg at the line:
    -Windows(GetStr(j)).Activate
    The error msg. is:
    -Compile error:
    -Sub or Function not defined
    Any idea why? And how to fix it?
  • To post as a guest, your comment is unpublished.
    Muralisk · 4 years ago
    Worked like a charm and it did save a lot of time and effort for me. Thanks.