Excel VBA: Insert Picture from Directory on Cell Value Change Without Error


Youtube Link : https://youtu.be/3BJaYVOy4TM

Code : This Code paste in Active sheet

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False

Dim myPict As Picture
Dim PictureLoc As String

If Target.Address = Range("b3").Address Then

ActiveSheet.Pictures.Delete

PictureLoc = "PICTURE LOCATION" & Range("b3").Text & ".jpg"

With Range("g3")
On Error GoTo errormessage:
Set myPict = ActiveSheet.Pictures.Insert(PictureLoc)

 myPict.Height = 300
 myPict.Width = 200
 myPict.Top = .Top
 myPict.Left = .Left
myPict.Placement = xlMoveAndSize
myPict.ShapeRange.LockAspectRatio = msoTrue

errormessage:
If Err.Number = 1004 Then

MsgBox "File does not Exist, Please first update photo with .jpg File"

End If
End With
End If
Application.ScreenUpdating = True
End Sub

Comments

Post a Comment

Popular posts from this blog

Excel VBA: Insert Multipul Picture from Directory on Cell Value Change Without