Hi Harish,
You have to capture the shape name while you are updating the image, then it will work.
Later you can hide the specified range from end user
Use this code:
Sub Chk_Insrt()
Dim fso As Object, MyDir As String, Nme As String, myPic As Object
Dim ws As Worksheet
Set fso = CreateObject("Scripting.FileSystemObject")
MyDir = "D:\New\" 'Change Directory
Nme = Sheets(1).[a1] & ".jpg" 'Change Filename
If fso.FileExists(MyDir & Nme) Then
Application.ScreenUpdating = 0
Set ws = Sheets(1) 'Change the target sheet
'--- Code Update-----
myshapename = ws.Range("k1").Value
ws.Shapes(myshapename).Delete
'end
Set myPic = ws.Pictures.Insert(MyDir & Nme)
With myPic
.Top = ws.[d5].Top
.Left = ws.[d5].Left
.ShapeRange.Height = ws.[d5].RowHeight * 4.2 '4.2 rows tall
End With
'--- Code Update-----
ws.Range("k1").Value = myPic.Name
'end
Set myPic = Nothing: Set ws = Nothing
Application.ScreenUpdating = 1
End If
Set fso = Nothing
End Sub
Regards,
Loki
Bookmarks