wie in einem anderem Post beschrieben (https://www.herber.de/forum/archiv/1656to1660/t1659184.htm) muss ich demnächst einige Listen pflegen. Dafür möchte ich nun auch PDFs automatisch einbetten lassen. Für Bilder habe ich folgendes :
Private Sub Worksheet_Change(ByVal Target As Range)
Dim shp As Shape
If Intersect(Target, [B:B]) Is Nothing Then Exit Sub
If Target.Row Mod 20 = 0 Then Exit Sub
On Error GoTo son
For Each shp In ActiveSheet.Shapes
If shp.Type = msoPicture And shp.TopLeftCell.Address = Target.Offset(0, 2).Address Then shp. _
Delete
Next
If Target.Value "" And Dir("C:\Users\Vincent\TEST\" & Target.Value & ".jpg") = "" Then
'picture not there!
MsgBox Target.Value & " Doesn't exist!"
End If
lngZeile = 5
ActiveSheet.Pictures.Insert("C:\Users\Vincent\TEST\" & Target.Value & ".jpg").Select
Selection.Top = Target.Offset(0, 2).Top
Selection.Left = Target.Offset(0, 2).Left
With Selection.ShapeRange
.LockAspectRatio = msoFalse
.Height = Target.Offset(0, 2).Height
.Width = Target.Offset(0, 2).Width
End With
Target.Offset(1, 0).Select
son:
End Sub
Private Sub Worksheet_Change2(ByVal Target As Range)
Dim objRange As Range, objCell As Range
Set objRange = Intersect(Target, Range)
If Not objRange Is Nothing Then
Application.EnableEvents = False
Range("A2:A3,B2:B3") = Environ$("USERNAME") & "," & CStr(Date)
Application.EnableEvents = True
End If
End Sub
Mit dem Makrorekorder habe ich eine PDF eingebettet und den Code dann wie folgt verändert:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim obj As OLEObjects
If Intersect(Target, [B:B]) Is Nothing Then Exit Sub
If Target.Row Mod 20 = 0 Then Exit Sub
On Error GoTo son
For Each obj In ActiveSheet.OLEObjects
If obj.Type = msoOLEObject And obj.TopLeftCell.Address = Target.Offset(0, 2).Address Then obj. _
Delete
Next
If Target.Value "" And Dir("C:\Users\Vincent\TEST_PDF\" & Target.Value & ".pdf") = "" Then
'picture not there!
MsgBox Target.Value & " Doesn't exist!"
End If
lngZeile = 5
ActiveSheet.OLEObjects.Add("C:\Users\Vincent\TEST_PDF\" & Target.Value & ".jpg", Link:=False, _
DisplayAsIcon:=True, IconFileName:= _
"C:\WINDOWS\Installer\{AC76BA86-1033-FFFF-7760-0C0F074E4100}\_PDFFile.ico", _
IconIndex:=0, IconLabel:="").Select
Selection.Top = Target.Offset(0, 2).Top
Selection.Left = Target.Offset(0, 2).Left
With Selection.ShapeRange
.LockAspectRatio = msoFalse
.Height = Target.Offset(0, 2).Height
.Width = Target.Offset(0, 2).Width
End With
Target.Offset(1, 0).Select
son:
End Sub
Das hat aber leider nicht funktioniert. Leider finde ich auch nicht das passende im Netz. Hat da jemand einen Vorschlag wie ich das hin bekommen könnte? Vielen Dank für die Hilfe :)!