Fehlermeldung bleibt die gleiche... der Code ist aber dieser (musste natürlich schon noch die richtige Spaltenzahl eingeben..., Sorry!)
Klappt aber immer noch nicht. Die Fehlermeldung bezieht sich auf "pfad =". Diese ist neben "Private Sub CommandButton1_Click()" ebenfalls markiert und scheint beim kompilieren nicht zu funktionieren...
Private Sub CommandButton1_Click()
Dim oExcelApp As Object
Dim oExcelWorkbook As Object
Dim lZeile As Long
If ListBox2.ListIndex >= 0 Then
Set oExcelApp = CreateObject("Excel.Application")
Set oExcelWorkbook = oExcelApp.Workbooks.Open(sAdressDatei)
lZeile = 2
With oExcelWorkbook.Sheets(sTabellenblatt)
Do While .Cells(lZeile, 1) <> ""
If ListBox2.Text = CStr(.Cells(lZeile, 2).Value) Then
ActiveDocument.Bookmarks("Linksunterschrift").Range.Text = _
CStr(.Cells(lZeile, 9).Value)
ActiveDocument.Bookmarks("Linksfunktion").Range.Text = _
CStr(.Cells(lZeile, 10).Value)
pfad = CStr(.Cells(lZeile, 11).Value)
ActiveDocument.Bookmarks("Bild").Range.InlineShapes.AddPicture FileName:=pfad, LinkToFile:=False, SaveWithDocument:=True
For i = 1 To ActiveDocument.InlineShapes
If ActiveDocument.InlineShapes(i).Type = 3 Then
ActiveDocument.InlineShapes(2).Width = 12
ActiveDocument.InlineShapes(2).Height = 6
Exit For
End If
Next i
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
|