ich weiß es handelt sich nicht um Excel, aber um VBA. Ich hab hier eine Word-Datei mit VBA die in anderen Word-Dateien, ein bestimmten Text sucht und durch einen anderen ersetzt. Soweit steht das VBA auch schon, nur hab ich hier das Porblem, dass nur auf der ersten Seite gesucht und ersetzt wird. Sobald die Word-Datei zwei Seiten hat, wird der gesuchte Text auf der zweiten Seite nicht gefunden und ersetzt. Ich hoffe jemand kann mir helfen.
hier der Quellcode
Sub test()
Dim b As Boolean
Do
b = Application.Dialogs(wdDialogFileOpen).Show
On Error Resume Next
ActiveDocument.Unprotect Password:=""
ActiveDocument.Unprotect Password:="wolke"
Dim objWord As Object, Kopfzeile As Object, Fusszeile As Object
Dim Pfad As String
Dim i As Integer
On Error Resume Next
If ActiveWindow.View.SplitSpecial wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.MoveDown Unit:=wdLine, Count:=4
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "523"
.Replacement.Text = "430"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "523"
.Replacement.Text = "430"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "523"
.Replacement.Text = "430"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveDocument.Protect wdAllowOnlyFormFields, True
ActiveDocument.Close True
Loop
End Sub