Option
Explicit
Sub
TextmarkenAnsteuern()
Dim
appWord
As
Object
Dim
wrdDocument
As
Object
On
Error
Resume
Next
Set
appWord = GetObject(,
"Word.Application"
)
If
Err = 429
Then
Err.Clear
Set
appWord = CreateObject(
"Word.Application"
)
If
Err > 0
Then
MsgBox
"Fehler beim Starten von Word!"
Exit
Sub
End
If
End
If
Err.Clear
Set
wrdDocument = appWord.Documents.Open(
"C:\Test\Test.docx"
)
If
Err = 1004
Then
MsgBox
"Dokument 'Test.doc' nicht vorhanden!"
appWord.Quit
Set
appWord =
Nothing
Exit
Sub
End
If
On
Error
GoTo
0
appWord.Visible =
True
wrdDocument.Bookmarks(
"Textmarke1"
).
Select
appWord.Selection.MoveLeft , ,
True
appWord.Selection.TypeText
"Mustertext Eins"
wrdDocument.Bookmarks(
"Textmarke2"
).
Select
appWord.Selection.MoveLeft , ,
True
appWord.Selection.TypeText
"Mustertext Zwei"
With
wrdDocument
.PrintOut
End
With
End
Sub