跳到主要内容

如何在Excel中将图像URL转换为实际图像?

doc url到img 1

如果现在在A列中有一个图像URL地址列表,那么您想从URL下载相应的图片,并将其显示在相邻的B列中,如左图所示。 在Excel中,如何快速,轻松地从图像URL中提取实际图片?

使用VBA代码将图像URL转换为实际图像

使用 Kutools for Excel 将图像 URL 转换为实际图像


使用VBA代码将图像URL转换为实际图像

以下VBA代码可以帮助您从图片URL地址中快速提取实际图片,请按以下步骤操作:

1。 按住 ALT + F11 键以打开“ Microsoft Visual Basic应用程序”窗口。

2。 点击 插页 > 模块,然后将以下代码粘贴到“模块窗口”中。

VBA代码:将图像URL转换为实际图像:

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("A2:A5")
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
If .Width > xRg.Width Then .Width = xRg.Width * 2 / 3
If .Height > xRg.Height Then .Height = xRg.Height * 2 / 3
.Top = xRg.Top + (xRg.Height - .Height) / 2
.Left = xRg.Left + (xRg.Width - .Width) / 2
End With
lab:
Set Pshp = Nothing
Range("A2").Select
Next
Application.ScreenUpdating = True
End Sub

笔记: 

  • 1.在上面的代码中, A2:A5 是包含您要提取图像的URL地址的单元格范围,则应根据需要更改单元格引用。
  • 2.使用此代码,您将无法根据需要指定提取图像的大小。
  • 3.上面的代码只能将实际图像提取到URL列之外的单元格中,您不能指定要输出图像的单元格。
  • 4.您应该对代码有一些基本的了解,如果任何字符丢失或不正确,则代码将无法成功执行。

3。 然后按 F5 键以运行此代码,并且所有对应的图片都已从图片网址中一次提取到相邻列中,并且这些图片将放置在您特定单元格的中央,请参见屏幕截图:

doc url到img 2


使用 Kutools for Excel 将图像 URL 转换为实际图像

如果您不熟悉VBA代码或想弥补上述代码的局限性, Kutools for Excel's 插入图片表格路径(URL) 该功能可帮助您根据计算机中的URL地址或特定路径快速插入对应的图像,如下图所示。 点击下载Kutools for Excel!

备注:申请这个 插入图片表格路径(URL),首先,您应该下载 Kutools for Excel,然后快速轻松地应用该功能。

安装后 Kutools for Excel,请这样做:

1。 点击 库工具 > 插页 > 插入图片表格路径(URL),在弹出的对话框中,请设置以下操作,请参见屏幕截图:

doc url到img 3 doc url到img 4

2。 然后,点击 Ok 按钮,图片将从URL中提取,请参见屏幕截图:

doc url到img 1

单击立即下载并免费试用 Kutools for Excel!

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (61)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
can anyone help to extract mutiple links folllowed by comma  in one cell 
This comment was minimized by the moderator on the site
I own Kutools and I cannot seem to get this function to work properly. After I run it based on the examples above I get a message that says "1 picture(s) failed to be inserted"
Its not an htpps address. And the link the works fine when clicking from excel.
Please help
This comment was minimized by the moderator on the site
I have the same problem now. It worked very well yesterday, but today it's just not working :(
This comment was minimized by the moderator on the site
If I want the image to resize with the cell, is it as simple as changing this line to "msoTrue"?.LockAspectRatio = msoFalse


This comment was minimized by the moderator on the site
When I renew it takes the same picture again
So it adds images on top of each other
how can i prevent this?
Do not add the added picture again ?how can I do?
edit: also pictures are not loading when we open later?
This comment was minimized by the moderator on the site
When I renew it takes the same picture againSo it adds images on top of each other
how can i prevent this?
Do not add the added picture again ?how can I do?
This comment was minimized by the moderator on the site
thank you for VBA code, i able to get the url images as picture
but, after file closed, and then i opened it again, picture missing.
how to solve this problem?
This comment was minimized by the moderator on the site
Hello, Robby,After copying and pasting the code, when you close the workbook, you should save the file as Excel Macro-Enabled Workbook format for saving the code.When reopen the workbook, you should click the Enable Content button from the yellow ribbon at the top of the workbook.Please try, thank you!
This comment was minimized by the moderator on the site
thank you for fast response
I have save as Excel Enable Workbook and also Enable Content, and Picture will be shown up if i connected to internet, but when offline mode, the picture will be missing, Excel message : Picture can't be display
is there any solution so the picture will still shown up even though i am in offline mode (no internet available)
This comment was minimized by the moderator on the site
Hi, Robby, In this case, if you are in offline mode, I recommend you to use the Insert Pictures form Path(URL) feature of Kutools for Excel, you can download the Kutools and use it 30 days for free trail. After inserting the pictures, the pictures will be saved into the workbook.Please try.
This comment was minimized by the moderator on the site
What image types does this work with? I have mostly svg files and those are not working, but png and jpeg are fine.
This comment was minimized by the moderator on the site
Hello, travwoody,Yes, as you said, the code does not work for the svg files.Or can you insert a picture url here? We can test your image url for modifying the code.Thank you!
This comment was minimized by the moderator on the site
Why this line is not working for me?
Set Pshp = Selection.ShapeRange.Item(1)
Pshp object is becoming nothing, even though I have a valid image URL
This comment was minimized by the moderator on the site
I will also specify that I am writing about the VBA script
This comment was minimized by the moderator on the site
This code works great. Thank you!
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations