Option
Explicit
Private
Const
sAdressDatei
As
String
= _
"adress.xlsx"
Private
Sub
CommandButton1_Click()
Dim
oExcelApp
As
Object
Dim
oExcelWorkbook
As
Object
Dim
lZeile
As
Long
If
ComboBox1.ListIndex >= 0
Then
Set
oExcelApp = CreateObject(
"Excel.Application"
)
Set
oExcelWorkbook = oExcelApp.Workbooks.Open(sAdressDatei)
lZeile = 2
With
oExcelWorkbook.sheets(
"firm"
)
Do
While
.Cells(lZeile, 1) <>
""
If
ComboBox1.Text =
CStr
(.Cells(lZeile, 2).Value)
Then
ActiveDocument.Bookmarks(
"Textmarke_BezDatei"
).Range.Text = _
CStr
(.Cells(lZeile, 3).Value)
ActiveDocument.Bookmarks(
"Textmarke_BezBetreff"
).Range.Text = _
CStr
(.Cells(lZeile, 4).Value)
ActiveDocument.Bookmarks(
"Textmarke_Auftragsnummer"
).Range.Text = _
CStr
(.Cells(lZeile, 5).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
Private
Sub
CommandButton2_Click()
Unload
Me
End
Sub
Private
Sub
Label1_Click()
End
Sub
Private
Sub
ComboBox1_Click()
End
Sub
Private
Sub
Label3_Click()
End
Sub
Private
Sub
UserForm_Initialize()
Dim
oExcelApp
As
Object
Dim
oExcelWorkbook
As
Object
Dim
lZeile
As
Long
Set
oExcelApp = CreateObject(
"Excel.Application"
)
Set
oExcelWorkbook = oExcelApp.Workbooks.Open(sAdressDatei)
ComboBox1.Clear
lZeile = 2
With
oExcelWorkbook.sheets(
"firm"
)
Do
While
.Cells(lZeile, 1) <>
""
ComboBox1.AddItem
CStr
(.Cells(lZeile, 2).Value)
lZeile = lZeile + 1
Loop
End
With
oExcelWorkbook.Close
False
oExcelApp.Quit
Set
oExcelWorkbook =
Nothing
Set
oExcelApp =
Nothing
End
Sub
ComboBox2
Option
Explicit
Private
Const
sAdressDatei
As
String
= _
"adress.xlsx"
Private
Sub
CommandButton1_Click()
Dim
oExcelApp
As
Object
Dim
oExcelWorkbook
As
Object
Dim
lZeile
As
Long
If
ComboBox2.ListIndex >= 0
Then
Set
oExcelApp = CreateObject(
"Excel.Application"
)
Set
oExcelWorkbook = oExcelApp.Workbooks.Open(sAdressDatei)
lZeile = 2
With
oExcelWorkbook.sheets(
"signature"
)
Do
While
.Cells(lZeile, 1) <>
""
If
ComboBox2.Text =
CStr
(.Cells(lZeile, 2).Value)
Then
ActiveDocument.Bookmarks(
"Textmarke_Unterschrift1"
).Range.Text = _
CStr
(.Cells(lZeile, 6).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
Private
Sub
CommandButton2_Click()
Unload
Me
End
Sub
Private
Sub
UserForm_Initialize()
Dim
oExcelApp
As
Object
Dim
oExcelWorkbook
As
Object
Dim
lZeile
As
Long
Set
oExcelApp = CreateObject(
"Excel.Application"
)
Set
oExcelWorkbook = oExcelApp.Workbooks.Open(sAdressDatei)
ComboBox2.Clear
lZeile = 2
With
oExcelWorkbook.sheets(
"signature"
)
Do
While
.Cells(lZeile, 1) <>
""
ComboBox2.AddItem
CStr
(.Cells(lZeile, 2).Value)
lZeile = lZeile + 1
Loop
End
With
oExcelWorkbook.Close
False
oExcelApp.Quit
Set
oExcelWorkbook =
Nothing
Set
oExcelApp =
Nothing
End
Sub