Function ShowPicD(PicFile As String) As Boolean
'Same as ShowPic except deletes previous picture when picfile changes
Dim AC As Range
Static P As Shape
On Error GoTo Done
Set AC = Application.Caller
If PicExists(P) Then
P.Delete
Else
'look for a picture already over cell
For Each P In ActiveSheet.Shapes
If P.Type = msoLinkedPicture Then
If P.Left >= AC.Left And P.Left < AC.Left + AC.Width Then
If P.Top >= AC.Top And P.Top < AC.Top + AC.Height Then
P.Delete
Exit For
End If
End If
End If
Next P
End If
Set P = ActiveSheet.Shapes.AddPicture(PicFile, True, True, AC.Left, AC.Top, 200, 200)
ShowPicD = True
Exit Function
Done:
ShowPicD = False
End Function
Function PicExists(P As Shape) As Boolean
'Return true if P references an existing shape
Dim ShapeName As String
On Error GoTo NoPic
If P Is Nothing Then GoTo NoPic
ShapeName = P.Name
PicExists = True
NoPic:
PicExists = False
End Function
gottimd said:When I select the specific picture, then yes it works, but that defeats the whole purpose of the Macro. Is there a way to do this?
The picnme = Cell p28. In this Cell P28 is the pictures name, which will change once data is refreshed. So how do I get it to recognize the extension of the jpg. Right now for instance, I have in Cell p28, "Money01.jpg"
Any ideas?
ActiveSheet.Pictures.Insert( _
"C:\Documents and Settings\Pictures\" & picnme & ".jpg").Select
Dim picnme As String
Dim rng As Range
Dim ArrImg
Set rng = Range("S27")
picnme = Range("P28")
If rng.Value = 1 Then
Range("C27").Select
ActiveSheet.Pictures.Insert( _
"C:\Documents and Settings\Pictures\" & picnme & ".jpg").Select
Selection.ShapeRange.IncrementLeft 162#
Selection.ShapeRange.IncrementTop 0.75
End If
End Sub