Excel将URL转换为图像(1004)

我有一个Excel文档链接到一个SQL数据库,其中包含几列图像的URL。

其中一个url如下所示: https : //imissit.blob.core.windows.net/iris/596480cf967e0c990c37fba3725ada0c/814040e2-0ccb-4b05-bdb3-d9dc9cc798d9/texture.png https://imissit.blob.core.windows.net/iris/596480cf967e0c990c37fba3725ada0c/814040e2-0ccb-4b05-bdb3-d9dc9cc798d9/texture.png

我发现如何将这些URL转换为图像不同的方法和方法(例如, Excel VBA插入图像从列中的图像名称和https://superuser.com/questions/940861/how-can-i-display-a-url- as-an-image-in-a-excel-cell )在excel文档中使用macros。 我尝试了这些方法,但没有一个适用于我的URL。 我尝试了其他URL(networking上的随机图像,http和https以及这些图像的工作原理)。

这是我尝试过的片段之一,适用于其他图片:

Sub InstallPictures() Dim i As Long, v As String For i = 2 To 2 v = Cells(i, "O").Value If v = "" Then Exit Sub With ActiveSheet.Pictures .Insert (v) End With Next i End Sub 

无论如何,当我尝试与我的URL我得到一个运行时错误1004:图片对象的插入方法无法执行(翻译)。 不同的方法会导致稍微不同的运行时错误(尽pipe1004是一致的)。

以下是我尝试过的一些图片url:

https://docs.oracle.com/cd/E21454_01/html/821-2584/figures/HTTPS_Collab_Sample.png

http://www.w3schools.com/css/paris.jpg

https://scontent.ftxl1-1.fna.fbcdn.net/v/t1.0-9/13043727_278733959131361_2241170037980408109_n.jpg?oh=bec505696c5f66cde0cc3b574a70547c&oe=58CC35C5

与我的url有什么不同?为什么这些方法不起作用? 什么是正确的方法?

问题(据我所知) 不是您的设备,但它是在托pipe图像的服务器上,并且无法返回文档。 我不知道Tim的上述评论(与206响应代码有关)来自哪里,但是如果是这种情况,或者URL返回了一些错误代码,那么你的VBA也会失败,并且可能没有什么可以做的要解决,如果问题出在主机上。

我今天手动inputURL并下载文件,没问题。

我检查响应代码 ,它正确返回200(成功)。

在这里输入图像说明

在这一点上,您可以做的最好的事情就是简单地捕捉错误,并将其标记出来供以后检查。

在我的testing中,我使用了一些故意的错误URL,以确保error handling按预期工作。 这些是我唯一失败的。

在这里输入图像说明

以下是我使用的代码,仅从您的代码中稍加修改,并包含一个error handling程序,以将注释添加到URL返回错误的单元格。 这样,您以后可以手动查看并根据需要添加这些图像。

 Sub InstallPictures() Dim i As Long Dim v As String Dim cl As Range Dim pic As Shape Dim errors As New Collection i = 2 Set cl = Cells(i, 15) Do While Trim(cl.Value) <> vbNullString v = Trim(cl.Value) cl.ClearComments With ActiveSheet.Pictures On Error GoTo ErrHandler Set p = .Insert(Trim(v)) On Error GoTo 0 ' I added this code to resize & arrange the pictures ' you can remove it if you don't need it p.TopLeftCell = cl.Offset(0, -1) p.Top = cl.Offset(0, -1).Top p.Left = cl.Offset(0, -1).Left p.Height = Cells(i, 15).Height p.Width = Cells(1, 15).Width ''''''''''''''''''''''''''''' End With NextCell: i = i + 1 Set cl = Cells(i, 15) Loop If errors.Count > 0 Then MsgBox "There were errors, please review the comments as some files may need to be manually downloaded" End If Exit Sub ErrHandler: Call ErrorNote(v, cl, errors) Resume NextCell End Sub Private Sub ErrorNote(url$, cl As Range, ByRef errs As Collection) ' Adds an item to the errs collection and flags the offending ' cell with a Comment indicating the error occurred. On Error Resume Next errs.Add (url) With cl .ClearComments .AddComment ("Error with URL: " & vbCrLf & url) End With End Sub