1

I am trying to insert a picture from a website into an excel sheet, but I get an error message, no matter which method I try.

The URL I use ("MyURL") is in the format:

https:// x.x.x.x:pppp/chart.png?id=10...apid=secretkey

But if I use any other picture url, it works... even if it has parameters, eg.:

http:// www.mrexcel.com/forum/avatars/[personsname].gif?dateline=2007

MyUrl works fine in any browser, but not in Excel.

I have used these methods:

A) Pictures.Insert

ActiveSheet.Pictures.Insert ("MyURL")

  • gives error: "Runtime error 1004: Unable to get the Insert property of the Pictures class"

B) Shapes.AddPicture

wsht.Shapes.AddPicture "MyURL", msoFalse, msoTrue, 0, 0, 100, 100

  • gives error: "Runtime error 1004: The specified file was not found"

C) Insert > Pictures > Paste URL in file name

  • gives error: "An error occurred while importing this file"

D) Convert MyUrl into a short URL

gives error:

  • A - "Insert method of picture class failed"

  • B - "The specified file was not found"

  • C - "An error occurred while importing this file"

My system: Windows 8, Excel 2013

What is the problem?

CodeMeHappy
  • 35
  • 1
  • 9

2 Answers2

2

Thanks for the help.

I found a work-around to the problem (not in Excel)... using VBscript to save the image, and then import it into Excel. The problem was with the security certificate. With the script the error is ignored.

dim xHttp: Set xHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
xHttp.setOption 2, 13056

dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", "MyURL", False

xHttp.Send

with bStrm
    .type = 1 '//binary
    .open
    .write xHttp.responseBody
    .savetofile "c:\BI\SyncScript\graph.png", 2 '//overwrite
end with
CodeMeHappy
  • 35
  • 1
  • 9
0

It may me related to your Internet Settings and/or Security Settings.............If you run this tiny macro with an empty sheet active:

Sub PictureGrabber()
    With ActiveSheet.Pictures
        .Insert ("http://www.dogbreedinfo.com/images26/PugPurebredDogFawnBlackMax8YearsOld1.jpg")
    End With
End Sub

What happens??

Gary's Student
  • 95,722
  • 10
  • 59
  • 99
  • Weird, it suddenly works... just used the code ActiveSheet.Pictures.Insert ("copy paste URL here"). Tnx ;) – CodeMeHappy Mar 06 '14 at 14:26
  • okay... now it is not working again... I did not change anything... will look into security settings. Any suggestions were to look? – CodeMeHappy Mar 06 '14 at 15:03
  • Hi Gary. your procedure works fine (no issues), but mine still does not work. When I use my URL I get a pop-up window (http://puu.sh/7lYfS.png), I say proceed, but then get the Run-time error '1004': "Insert method of picture class failed". – CodeMeHappy Mar 07 '14 at 06:52