Ich habe ein Excel-Arbeitsblatt, das ich als druckbare Einzelseite PDF-Bericht verwenden, die ein Bild mit etwas Text enthält. In einer Spalte neben mir habe ich eine Liste aller Bilder in einem bestimmten Ordner und ich möchte VBA verwenden, um durch die Liste zu navigieren, die das Bild im Arbeitsblatt ersetzt und eine PDF erstellt, die im selben Ordner gespeichert wird. Ich mache das derzeit manuell, was ein Problem ist und ich möchte es mit VBA automatisieren.Excel VBA Bild ersetzen, PDF erstellen, zum nächsten Bild im Ordner wechseln und
Jede Hilfe würde sehr geschätzt werden.
Vielen Dank im Voraus.
Der Code i manualy verwenden, indem Sie den vollständigen Pfad des Bildes ändert ersetzt werden wird wie folgt>
Sub AddPicturesFULL()
Dim myPic As Picture
Dim wkSheet As Worksheet
Dim myRng As Range
Dim myCell As Range
Dim rowCount As Long
Dim rowCount2 As Long
Dim Pic As Object
Set wkSheet = Sheets("REPORT(FULL)") ' -- Change to your sheet
For Each Pic In wkSheet.Pictures
Pic.Delete
Next Pic
'-- The usual way of finding used row count for specific column
rowCount2 = wkSheet.Cells(wkSheet.Rows.Count, "N").End(xlUp).Row
If rowCount2 <> 0 Then
Set myRng = wkSheet.Range("N2", wkSheet.Cells(wkSheet.Rows.Count, "N").End(xlUp))
For Each myCell In myRng.Cells
If Trim(myCell.Value) = "" Then
'MsgBox "No file path"
ElseIf Dir(CStr(myCell.Value)) = "" Then
MsgBox myCell.Value & " Doesn't exist!"
Else
'myCell.Offset(0, 1).Parent.Pictures.Insert (myCell.Value)
Set myPic = myCell.Parent.Pictures.Insert(myCell.Value)
With myCell.Offset(0, -13) '1 columns to the right of C (is D)
'-- resize image here to fit into the size of your cell
myPic.Top = .Top
myPic.Width = .Width
myPic.Height = 640
myPic.Left = .Left
myPic.Placement = xlMoveAndSize
myPic.SendToBack
End With
End If
Next myCell
Else
MsgBox "There is no file paths in your column"
End If
End Sub
Dies scheint nicht zu funktionieren. Ich habe COLUMN durch "A" ersetzt, wo meine vollständigen Pfade angezeigt werden. Ich erhalte einen "Fehler 481 - Ungültiges Bild". Meine Bilder sind .tif-Format, falls das einen Unterschied macht. Irgendwelche Vorschläge? – burt46
In der Cells-Funktion müssen Sie eine Ganzzahl anstelle eines Zeichens verwenden. also benutze 1 statt A, 2 statt B und so weiter. .TIF wird vom ActiveX-Image nicht unterstützt. Also musst du etwas anderes versuchen. Sorry – gizlmo
Ok, irgendwelche anderen Ideen oder wie ich meinen ursprünglichen Code oben ändern kann – burt46