有人可以向我解释如何将网络链接(URL)转换为图像。
示例图片(网址为http://cache.lego.com/media/bricks/5/1/4667591.jpg)

我想要做的是制作一个我下载的零件清单显示图像而不是上面的网络链接。
我在 J2 到 J1903 中的内容是:
http://cache.lego.com/media/bricks/5/1/4667591.jpg
http://cache.lego.com/media/bricks/5/1/4667521.jpg
...
Run Code Online (Sandbox Code Playgroud)
我想要做的是让 excel 将所有这些(其中 10903 个)转换为图片(单元格大小 81x81)。
有人可以一步一步解释我如何做到这一点吗?
如果您在J列中有一组链接,例如:

然后运行这个简短的 VBA 宏:
Sub InstallPictures()
Dim i As Long, v As String
For i = 2 To 1903
v = Cells(i, "J").Value
If v = "" Then Exit Sub
With ActiveSheet.Pictures
.Insert (v)
End With
Next i
End Sub
Run Code Online (Sandbox Code Playgroud)
每个链接都将被打开,相关的图片将被放置在工作表上。
图片的大小和位置必须正确。
编辑#1:
宏非常易于安装和使用:
如果您保存工作簿,宏将与它一起保存。如果您使用的是 2003 年以后的 Excel 版本,则必须将文件另存为 .xlsm 而不是 .xlsx

要删除宏:
要使用 Excel 中的宏:
要了解有关一般宏的更多信息,请参阅:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
和
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
必须启用宏才能使其工作!
编辑#2:
为避免因检索错误而停止,请使用此版本:
Sub InstallPictures()
Dim i As Long, v As String
On Error Resume Next
For i = 2 To 1903
v = Cells(i, "J").Value
If v = "" Then Exit Sub
With ActiveSheet.Pictures
.Insert (v)
End With
Next i
On Error GoTo 0
End Sub
Run Code Online (Sandbox Code Playgroud)
小智 6
这是我的修改:
代码如下:
Option Explicit
Dim rng As Range
Dim cell As Range
Dim Filename As String
Sub URLPictureInsert()
Dim theShape As Shape
Dim xRg As Range
Dim xCol As Long
On Error Resume Next
Application.ScreenUpdating = False
' Set to the range of cells you want to change to pictures
Set rng = ActiveSheet.Range("A2:A600")
For Each cell In rng
Filename = cell
' Use Shapes instead so that we can force it to save with the document
Set theShape = ActiveSheet.Shapes.AddPicture( _
Filename:=Filename, linktofile:=msoFalse, _
savewithdocument:=msoCTrue, _
Left:=cell.Left, Top:=cell.Top, Width:=60, Height:=60)
If theShape Is Nothing Then GoTo isnill
With theShape
.LockAspectRatio = msoTrue
' Shape position and sizes stuck to cell shape
.Top = cell.Top + 1
.Left = cell.Left + 1
.Height = cell.Height - 2
.Width = cell.Width - 2
' Move with the cell (and size, though that is likely buggy)
.Placement = xlMoveAndSize
End With
' Get rid of the
cell.ClearContents
isnill:
Set theShape = Nothing
Range("A2").Select
Next
Application.ScreenUpdating = True
Debug.Print "Done " & Now
End Sub
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
124713 次 |
| 最近记录: |