Advertisement
YasserKhalil2019

T4092_Display Picture From Folder By Name In Worksheet Event

Oct 11th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. https://excel-egy.com/forum/t4092
  2. ---------------------------------
  3.  
  4. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  5. Dim shp As Object, c As Range, sPath As String
  6.  
  7. If Target.Count > 1 Then Exit Sub
  8.  
  9. If Not Intersect(Target, Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)) Is Nothing Then
  10. For Each shp In ActiveSheet.Pictures: shp.Delete: Next shp
  11. If IsEmpty(Target) Then Exit Sub
  12. sPath = ActiveWorkbook.Path & "\Pictures\" & Target.Offset(0, 1) & ".jpg"
  13.  
  14. If Dir(sPath) <> "" Then
  15. Set c = Target.Offset(, 2)
  16. With ActiveSheet.Pictures.Insert(sPath)
  17. .Left = c.Left
  18. .Top = c.Top
  19. .Placement = xlMove
  20. End With
  21. Application.Goto Target, True
  22. End If
  23. End If
  24. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement