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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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