Suchen und Ersetzen in Word von Excel aus
22.08.2003 21:38:04
Wolfgang Sandten
habe folgendes Problem: möchte per Excel-VBA in Word eine Textdatei einlesen und dort alle Kommata durch einen Punkt ersetzen. Das Programm läuft wunderbar... bis auf den Fehler, dass die Wordkonstanten "wdFindContinue" und (was viel schlimmer ist) "wdReplaceAll" einen Fehler auslösen ("Variable nicht definiert").
Kann mir jemand sagen, was ich falsch mache?
Herzlichen Dank!!
Wolfgang Sandten
===================================
Mein Programmcode:
Sub OpenWordDocument()
On Error GoTo Fehler
Dim oWord As Object
Application.StatusBar = "Bereinige ALO_LE in Word..."
Set oWord = CreateObject("word.application")
oWord.Application.Visible = True
oWord.Application.Documents.Open "C:\TEMP\ALO_LE.TXT"
oWord.Selection.Find.Replacement.ClearFormatting
With oWord.Selection.Find
.Text = ","
.Replacement.Text = "."
.Forward = True
.Wrap = wdFindContinue'<---- Fehler!!!
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
oWord.Selection.Find.Execute Replace:=wdReplaceAll'<----- Fehler!!!!
oWord.Application.Quit (True)
Set oWord = Nothing
Application.StatusBar = False
Exit Sub
Fehler:
Application.StatusBar = False
oWord.Application.Quit (True)
Set oWord = Nothing
MsgBox Err.Number & " " & Err.Description, vbCritical, "SQL_PIVOT"
End Sub