Excel VBA Inserted Pictures Are Now Links

them2854

New Member
Joined
May 1, 2017
Messages
1
I am unsuccessfully trying to adjust code that was created by a previous coworker. I have very limited VBA experience, so please bare with me. Currently use this code below. It is attached to a button on an excel worksheet, this inserts an image into a specified range of cells, it resizes the image then lands on a cell below to type the description. The problem we are having is our template is now being moved from our server to outside locations. So all of the images are now just broken links. I have attempted several adjustments, but none so far would insert the actual image instead of linking it.

Code:
Private Sub Picture1_Click()
' Select Image From File
    With Application.FileDialog(msoFileDialogFilePicker)
        If .Show Then
        PicLocation = .SelectedItems(1)
 
        Else
        PicLocation = ""
        End If
    End With
    
    ' Error Check
    If PicLocation = "" Then
    MsgBox "No picture selected"
        Exit Sub
    End If
    
    'Initialization
    Dim TargetCells As Range
 
    ActiveSheet.Unprotect
    Set TargetCells = Range("B9:H24")
    
    ' Error check 2
    If PicLocation <> "False" Then
        Set p = ActiveSheet.Pictures.Insert(PicLocation)
    Else
        Exit Sub
    End If
    
    ' Set image dimensions
    With p.ShapeRange
        .LockAspectRatio = msoTrue
            .Height = TargetCells.Height
            If .Width > TargetCells.Width Then .Width = TargetCells.Width
    End With
    
    ' Set image location
    With p
        .top = TargetCells.top
        .Left = TargetCells.Left
        .PrintObject = True
    End With
 
     ' Close out operations
    Range("a25").Select
    
    Set p = Nothing
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,214,971
Messages
6,122,517
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top