Sub
WordDokumentöffnen(
ByVal
Dokumente
As
String
)
Const
wdReplaceAll = 2
Dim
AppWD
As
Object
, AppDoc
As
Object
If
Dir(Dokumente) <>
""
Then
Set
AppWD = CreateObject(
"Word.Application"
)
If
Not
AppWD
Is
Nothing
Then
AppWD.Visible =
True
If
AppWD.Options.AllowReadingMode =
True
Then
AppWD.Options.AllowReadingMode =
False
End
If
Set
AppDoc = AppWD.Documents.Open(Dokumente)
If
AppWD.ActiveDocument.ProtectionType <> wdNoProtection
Then
AppWD.ActiveDocument.Unprotect
End
If
If
Not
AppDoc
Is
Nothing
Then
With
AppDoc.Range.Find
.Text =
"Test"
.MatchCase =
True
.Replacement.Highlight =
True
.Replacement.Text = ActiveWorkbook.Sheets(
"Eingabefenster"
).Range(
"B5"
).Value
.Execute Replace:=wdReplaceAll
End
With
AppWD.Documents.Close (Dokumente)
End
If
End
If
Else
MsgBox
"Die zu öffnende Dokumentdatei wurde nicht gefunden!"
, vbCritical,
"Word-Datei öffnen"
End
If
Set
AppWD =
Nothing
Set
AppDoc =
Nothing
End
Sub