Excel Place Local Pictures In Cell Using Formula and a VBA Hack - Episode 2607a


This page contains the sample files for the following MrExcel video on YouTube.

Excel Place Local Pictures In Cell Using Formula and a VBA Hack - Episode 2607a

Download Sample Files »




VBA Code to Replace image path with Image:

Sub ReplacePathWithImage()
    Dim OrigSelection As Range
    Set OrigSelection = Selection
    For Each cell In Selection
        ThisPath = cell.Value
        cell.Clear
        Err.Clear
        On Error Resume Next
        cell.Select
        Selection.InsertPictureInCell (ThisPath)
         If Err.Number <> 0 Then cell.Value = ThisPath
    Next cell
    OrigSelection.Select
End Sub

VBA Code to put image to right of cell containing image path:

Sub AddImageToRight()
    Dim OrigSelection As Range
    Set OrigSelection = Selection
    For Each cell In Selection
        ThisPath = cell.Value
        HoldRight = cell.Offset(0, 1).Value
        cell.Offset(0, 1).Clear
        Err.Clear
        On Error Resume Next
        cell.Offset(0, 1).Select
        Selection.InsertPictureInCell (ThisPath)
         If Err.Number <> 0 Then Selection.Value = HoldRight
    Next cell
    OrigSelection.Select
End Sub


* If you find the sample file(s) helpful, please leave a Super Thanks using the icon below the video.


Step 1


Step 2