Private
Sub
CommandButton1_Click()
Dim
oExcelApp
As
Object
Dim
oExcelWorkbook
As
Object
Dim
lZeile
As
Long
If
ListBox1.ListIndex >= 0
Then
Set
oExcelApp = CreateObject(
"Excel.Application"
)
Set
oExcelWorkbook = oExcelApp.Workbooks.Open(sBeispiel)
lZeile = 2
With
oExcelWorkbook.sheets(sTabellenblatt)
Do
While
.Cells(lZeile, 1) <>
""
If
ListBox1.Text =
CStr
(.Cells(lZeile, 2).Value)
Then
ActiveDocument.Bookmarks(
"Textmarke_Name "
).Range.Text = _
CStr
(.Cells(lZeile, 2 ).Value)
ActiveDocument.Bookmarks(
"Textmarke_ID"
).Range.Text = _
CStr
(.Cells(lZeile, 1).Value)
ActiveDocument.Bookmarks(
"Textmarke_Beschreibung"
).Range.Text = _
CStr
(.Cells(lZeile, 3).Value)
Exit
Do
End
If
lZeile = lZeile + 1
Loop
End
With
oExcelWorkbook.Close
False
oExcelApp.Quit
Else
MsgBox
"Bitte wählen Sie einen Eintrag aus der Liste aus!"
, _
vbInformation + vbOKOnly,
"HINWEIS!"
Exit
Sub
End
If
Set
oExcelWorkbook =
Nothing
Set
oExcelApp =
Nothing
Unload
Me
End
Sub