babybluebentley
New Member
- Joined
- Mar 24, 2022
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
- MacOS
Hi,
I already have a VBA that inserts the corresponding image next to a file path. Works fine so far
-> file(image) paths are in column C, images gets added into cell next to path
My problem is: As I generate the image path via a formula, not every file path actually has an image. My tool should actually check whether or not there is an image for this path or not, so I would like to have a TRUE if there is an image and a FALSE if there is no image. I think i makes sense to add this marker next to the image.
I already tried to create a formula to check it, works, but its way to slow and Excel crashed after two hours. This is the code i tired:
Now I need a code that combines both and tires to mark if an image got added successfully next to a file path. Alternatively, a code that checks if a file exists with the file path in column C
I would be extremely happy if someone could help.
I already have a VBA that inserts the corresponding image next to a file path. Works fine so far
VBA Code:
Sub AddImageFromPath()
Dim xRg As Range
Dim xCell As Range
Dim xVal As String
On Error Resume Next
Set xRg = Application.Range("C2:C10000")
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
For Each xCell In xRg
xVal = xCell.Value
If xVal <> "" Then
ActiveSheet.Shapes.AddPicture xCell.Value, msoFalse, msoTrue, _
xCell.Offset(0, 1).Left, xCell.Top, xCell.Height, _
xCell.Height
End If
Next
Application.ScreenUpdating = True
End Sub
My problem is: As I generate the image path via a formula, not every file path actually has an image. My tool should actually check whether or not there is an image for this path or not, so I would like to have a TRUE if there is an image and a FALSE if there is no image. I think i makes sense to add this marker next to the image.
I already tried to create a formula to check it, works, but its way to slow and Excel crashed after two hours. This is the code i tired:
Code:
Function HASpic(Cell As Range) As Boolean
Dim Caddress As String
Dim Pict As Object
Application.Volatile
Caddress = Cell.Address
For Each Pict In Application.Caller.Parent.Pictures
If Pict.TopLeftCell.Address = Caddress Then
HASpic = True
Exit Function
End If
Next Pict
HASpic = False
End Function
Now I need a code that combines both and tires to mark if an image got added successfully next to a file path. Alternatively, a code that checks if a file exists with the file path in column C
I would be extremely happy if someone could help.