Hallo,
ich suche einen einfacheren weg als meinen, um eine bestimmte Zeichenkette mit einer anderen zu ersetzen. Und zwar im ganzen Dokument.
Mein Makro ruft mit den folgenden Zeilen die Public Sub(Repeat) auf:
Dim lCount As Integer
Number_of_Changes = 1
lsNewString(1) = "<#" & bmBookmark.Name & "#>"
lsOldString(1) = "%" & bmBookmark.Name & "%"
----------------------------------------------------------------------
For lCount = 1 To Number_of_Changes
For Each MyStoryRange In ActiveDocument.StoryRanges
Call Repeat(MyStoryRange, lsOldString(lCount), lsNewString(lCount))
Next MyStoryRange
Next lCount
-----------------------------------------------------------------------
Public Sub Repeat(ReplaceIn As Range, ByVal FindText As String, ByVal ReplacementText As String)
Dim bResult As Boolean
Dim IsNewString As String
Dim IsOldString As String
Dim MyAR() As String
Dim i As Long
i = 0
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
'Selection.Find.Font.Color = -738132071
With Selection.Find
.Text = FindText
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
'If Selection.Find.Found = True Then
Do While Selection.Find.Execute = True
With Selection
.Font.Size = 8
.Font.ColorIndex = wdViolet
.Font.Bold = True
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"QUOTE" & " " & ReplacementText, PreserveFormatting:=True
End With
ReDim Preserve MyAR(i)
MyAR(i) = Selection
i = i + 1
Loop
|