excel - Excel VBA 图片插入不起作用 - 仅适用于某些 URL
问题描述
我使用下面的 VBA 代码从图像 URL 插入图片。出于某种原因,此代码适用于某些图像 URL,但不适用于其他 URL。
例如,以下 URL 将起作用
http://a.espncdn.com/combiner/i?img=/i/headshots/nfl/players/full/3123076.png&w=350&h=254
但下面不会
http://ecx.images-amazon.com/images/I/41HkOMYqc9L.SL500.jpg
http://ecx.images-amazon.com/images/I/41gWzC%2B5IqL.SL500.jpg
http://ecx.images-amazon.com/images/I/41gWzC%2B5IqL.SL500.jpg
有谁知道“ActiveSheet.Pictures.Insert”命令是否有任何限制?
下面是我正在使用的代码
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("A1 :A24")
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 + 1
Set xRg = Cells(cell.Row, xCol)
With Pshp
.LockAspectRatio = msoFalse
.Width = 100
.Height = 100
.Top = xRg.Top + (xRg.Height - .Height) / 2
.Left = xRg.Left + (xRg.Width - .Width) / 2
End With
lab:
Set Pshp = Nothing
Range("A1").Select
Next
Application.ScreenUpdating = True
End Sub
解决方案
推荐阅读
- python - Scipy stats.rv_continuous 从二维数据中查找 MLE
- javascript - 文本框 onChange 事件和 Datepicker onSelect 冲突
- java - 填充在 GeometricObject 中具有私有访问权限
- javascript - react native 中的获取请求没有得到完整的网页
- c++ - 多维非常大的数组 C++
- python-3.x - 结合高阶函数以使用文本文件从数字列表中计算平均值
- kotlin - 如何在 Kotlin 中将字符串语句转换为数组列表
- javascript - 带按钮功能的图像排序
- logback - Apache Flink:logback 配置被忽略
- javascript - 为什么数据加倍,我该如何解决?