01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 |
|
Sub Test()
' Early Binding =>Verweis auf Wordbibliothek muss gesetzt sein
Dim appWD As New Word.Application, oDoc As Word.Document
Dim sErsetz() As String, i As Integer
' Suchbegriff1,Feld1, Suchbegriff2,Feld2, Suchbegriff3,Feld3 .....
sErsetz = Split("#Jahr#,A1,#Attribut#,B1", ",")
Const csWorddatei = "C:\Users\volti\Documents\Worddokumente\Test.docm"
appWD.WordBasic.DisableAutoMacros ' Makros ausschalten
Set oDoc = appWD.Documents.Open(Filename:=csWorddatei)
appWD.Visible = True ' Word sichtbar
With oDoc.Range.Find
.ClearFormatting
.Replacement.ClearFormatting ' Zurücksetzen
.MatchWholeWord = True ' Ganze Wörter
.MatchCase = False ' Groß-Kleinschreibung
For i = 0 To UBound(sErsetz) Step 2 ' Anzahl Suchbegriffe
.Text = sErsetz(i)
.Replacement.Text = Range(sErsetz(i + 1))
.Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue
Next i
End With
oDoc.Save ' Dokument speichern
oDoc.Close SaveChanges:=False ' Dokument schließen ohne speichern
appWD.Quit ' Word schließen
Set oDoc = Nothing: Set appWD = Nothing
End Sub
|