Excel VBA - How to extract the image from url and embed in excel?

nkaggarwal1

New Member
Joined
Dec 9, 2018
Messages
14
I am trying to extract the image from url and embed in excel 2007.
My Excel is simple , it contains 2 columns , Column 1 has the image url and in other column i want the embed the image. i am using the attached code , it is working perfectly fine for first row where i have saved the image from url in my local machine and given the path but fails when extracting from url.
Error - Run time 1004 , unable to get the insert property for the picture class.


Code Used-
Code:
Sub Button1_Click()
Dim Pshp As Shape

Dim xRg As Range

Dim xCol As Long

'On Error Resume Next

Application.ScreenUpdating = False

Set Rng = ActiveSheet.Range("A2:A3")

MsgBox "Step1"

For Each cell In Rng

    filenam = cell

    MsgBox "Step2" & cell

    ActiveSheet.Pictures.Insert(filenam).Select

    MsgBox "Step3"

    Set Pshp = Selection.ShapeRange.Item(1)

    'MsgBox "Step4" & Pshp

    If Pshp Is Nothing Then GoTo lab

    xCol = cell.Column + 1

    Set xRg = Cells(cell.Row, xCol)

    With Pshp

        .LockAspectRatio = msoFalse

        .Width = 80

       .Height = 80

        .Top = xRg.Top + (xRg.Height - .Height) / 2

        .Left = xRg.Left + (xRg.Width - .Width) / 2

    End With
Set Pshp = Nothing

Range("A2").Select

Next

Application.ScreenUpdating = True
End Sub
Can this be problem with the excel vba references.
 
Last edited by a moderator:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi

Maybe you can post one of your url's so that we can try.

This is a simple example you can try with MrExcel logo:

Code:
Sub Test()
Dim sAddr As String
Dim pic As Picture

sAddr = "https://www.mrexcel.com/forum/images/misc/mrexcelvb_logo.png"
Set pic = ActiveSheet.Pictures.Insert(sAddr)

With pic.ShapeRange
    .LockAspectRatio = msoFalse
    .Width = 80
    .Height = 80
End With

End Sub
 
Upvote 0
Thanks PGC , I tried this in fresh xls , but got the same error

Error - Run time 1004 , unable to get the insert property for the picture class.

The error occured at below lineSet pic = ActiveSheet.Pictures.Insert(sAddr)

Can this be problem with the VB refrences?. My current references are-



Kindly advise.

Thanks,

Nishant.
 
Upvote 0
Hi

Did you read your post?

1 - You cannot see the references
2 - even if you could see them, it would be a picture. How do you get the references out of a picture?

Please post the references so that we can try.
 
Upvote 0
P. S.

Maybe you can see the picture because your pc has access to the file?

C:\Users\gzb\Desktop\Monti\Final\Finalest\Reference.png

We, however, don't.

Please post the references as text.
 
Upvote 0
Sorry , Please find the details below-

Excel version - 2007

References in order-

Visual Basic for Applications
Microsoft Excel 12.0 Object Library
Microsoft Internet Controls
Microsoft HTML Object Library
OLE Automation
Microsoft Office 12.0 Object Library.

Kindly Advise,

Thanks!!

Nishant.
 
Upvote 0
I'm sorry, this was a misunderstanding.

I mean the url reference to one of your images, so that we can try the code to insert it in the worksheet.
 
Upvote 0
Hi PGC, I tried your code only in fresh new excel and faced the same issue. If that works I hope my url will also work. Kindly advise.
 
Upvote 0
Error - Run time 1004 , unable to get the insert property for the picture class.

Are you sure that the worksheet is not protected?
This would be the error displayed if your try to insert the picture in a protected worksheet.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
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