VBA URLPictureInsert pics disappear

Landshark24

New Member
Joined
Oct 27, 2019
Messages
6
Hi there,

I have VBA to insert images from a filepath which is derived from a formula. The images insert just fine and are visible for me but if someone else opens the documents they cannot be seen (all settings are correct). I'm assuming I need to embed the images but cannot quite get the code correct. Here is the original code:
Code:
Sub URLPictureInsert()
    Dim Pshp As Shape
    Dim xRg As Range
    Dim xCol As Long
    
    On Error Resume Next
    Application.ScreenUpdating = False
    Set Rng = ActiveSheet.Range("B52")
    For Each cell In Rng
    filenam = cell
    ActiveSheet.Pictures.Insert(filenam).Select
    Set Pshp = Selection.ShapeRange.Item(1)
    If Pshp Is Nothing Then GoTo lab
    xCol = cell.Column
    Set xRg = Cells(cell.Row, xCol)
    With Selection
            .ShapeRange.LockAspectRatio = msoTrue
            If (.Height \ .Width) <= (Rng.Height \ Rng.Width) Then
                .Width = Rng.Width - 1
                .Left = Rng.Left + 1
                .Top = Rng.Top + ((Rng.Height - Selection.Height) / 2)
            Else
                .Top = Rng.Top + 1
                .Height = Rng.Height - 1
                .Left = Rng.Left + ((Rng.Width - Selection.Width) / 2)
            End If
            
            .Placement = xlMoveAndSize
            .PrintObject = True
    End With
lab:
    Set Pshp = Nothing
    Range("B52").Select
    Next
    Application.ScreenUpdating = True
End Sub
Any suggestions much appreicated

NOTE: Have tried simply copying and pasting the images after the VBA is run, but it seems to only work sometimes. Other times the image are still unavailable
 
Last edited by a moderator:

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Pictures.insert method has been deprecated. Try Shapes.AddPicture.
 
Upvote 0
@yky thank yo so much for the quick reply. I am a bit of a vba novice and I don't think I'm adjusting the code correctly. Do you mind showing me how to amend the original code?
 
Upvote 0

Forum statistics

Threads
1,214,647
Messages
6,120,722
Members
448,987
Latest member
marion_davis

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