[英]Excel VBA getting an image from url
I'm making a macro on Excel 2013 to get the URL from a column (Column "f") and put it on the next column (Column "G") I already make a code but it doesn't work as I want 我在Excel 2013上制作了一个宏,以从列(“ f”列)获取URL并将其放在下一个列(“ G”列)中,我已经编写了代码,但是按我的意愿无法使用
Sub GetShapeFromWeb(strShpUrl As String, rngTarget As Range)
With rngTarget.Parent
.Pictures.Insert strShpUrl
.Shapes(.Shapes.Count).Left = rngTarget.Left
.Shapes(.Shapes.Count).Top = rngTarget.Top
End With
End Sub
Sub Obtener_imagen()
On Error Resume Next
For i = 2 To 3
Call GetShapeFromWeb(Range("f" & i).Value, Hoja1.Range("a65536").End(xlUp).Offset(6, i))
Next i
End Sub
The problem is that you're putting this in the Range Range("a65536").End(xlUp).Offset(6, i)
问题是您将其放在Range
Range("a65536").End(xlUp).Offset(6, i)
So you're offsetting by i
from column A. Change that i
to a 7
to specify column G, or another variable if you need it dynamic. 因此,您要从列A偏移
i
。将i
更改为7
以指定列G,或者如果需要动态则将其更改为另一个变量。
Your range statement is doing the following: 您的range语句正在执行以下操作:
.Offset(6
) .Offset(6
) This will cause you problems if column A doesn't have the same number of rows populated as column G, and it also sounds like you don't want to offset by 6 rows either. 如果A列填充的行数与G列填充的行数不同,这将给您带来问题,而且听起来您也不想偏移6行。
If I understand correctly, this is what you are trying to achieve 如果我理解正确,这就是您要实现的目标
Sub Obtener_imagen()
Dim fila as Integer,ultima_fila as Integer
ultima_fila =Hoja1.Range("F65536").End(xlUp).row
For fila =1 To ultima_fila
With Range("G" & fila).Parent
.Pictures.Insert Range("F" & fila)
.Shapes(.Shapes.Count).Left = ("G" & fila).Left
.Shapes(.Shapes.Count).Top = ("G" & fila).Top
End With
Next i
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.