Change VBA code to get embedded image not link [Closed]

Report
Posts
1
Registration date
Saturday August 26, 2017
Status
Member
Last seen
August 26, 2017
-
Hi everyone,

I have a VBA code, which inserts image into excel based on the cell value entered in coloumn A. My problem is that image is a link, and when I share the file with people out of network, they can't see the image. I researched, and I see that "Pictures.Insert" should be changed to "Shapes.AddPicture", but I do something wrong and get error.
Can you please help with this?
here is the code, I want to modify:


Private Sub Worksheet_Change(ByVal Target As Range)
If (Split(Target.Address, "$")(1) <> "A") Then Exit Sub

Dim c As Range
Dim myPath As String
myPath = "C:\Users\ED\Pictures\"
Application.ScreenUpdating = False

For Each c In Target.Cells
If Not Dir(myPath & "*" & c.Text & "*") = "" Then
InsertPicture myPath & Dir(myPath & "*" & c.Text & "*"), c.Offset(0, 1)
End If
Next c
Application.ScreenUpdating = True

End Sub


Sub InsertPicture(thePath As String, theRange As Range)

With ThisWorkbook.ActiveSheet.Pictures.Insert(thePath)
With .ShapeRange
.LockAspectRatio = msoTrue
.Width = theRange.Width
.Height = theRange.Height
End With
.Left = theRange.Left
.Top = theRange.Top
.Placement = 1
.PrintObject = True
End With

End Sub