ExcelTip.Net留存知识帖 ---【注:附件之前被网盘供应商清空后,现已修复-现已修复-现已修复为本地下载!】
现在位置:首页 > 我的酷贴 > Excel VBA > 如何采集网页动态图片

如何采集网页动态图片

作者:绿色风 分类: 时间:2022-08-18 浏览:53
楼主
xmyjk
Q:如何获取网页图片,链接为:http://hqgjqhpic.eastmoney.com/EM_Futures2010PictureProducter/Picture/GLNC0R.png,至EXCEL中,图片是动态更新的,要随时能更新。


A:
  1. Option Explicit
  2. Sub test()
  3.     Dim xmlhttp As Object, Adodb As Object, shp As Shape
  4.    
  5.     For Each shp In Worksheets(1).Shapes
  6.        If shp.Name Like "Picture*" Or shp.Name Like "图片*" Then shp.Delete
  7.     Next
  8.         
  9.     If Dir(ThisWorkbook.Path & "\" & "1" & ".gif") <> "" Then Kill (ThisWorkbook.Path & "\" & "1" & ".gif")
  10.    
  11.     Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
  12.     With xmlhttp
  13.         .Open "get", "http://hqgjqhpic.eastmoney.com/EM_Futures2010PictureProducter/Picture/GLNC0R.png?" & Rnd(), False
  14.         .send
  15.     End With
  16.     Set Adodb = CreateObject("ADODB.Stream")
  17.     With Adodb
  18.         .Type = 1
  19.         .Open
  20.         .write xmlhttp.Responsebody
  21.         .savetofile ThisWorkbook.Path & "\" & "1" & ".gif", 2
  22.         .Close
  23.     End With
  24.    
  25.     Set xmlhttp = Nothing
  26.     Set Adodb = Nothing
  27.    
  28.     ActiveSheet.Pictures.Insert (ThisWorkbook.Path & "\" & "1" & ".gif")
  29.     'If Dir(ThisWorkbook.Path & "\" & "1" & ".gif") <> "" Then Kill (ThisWorkbook.Path & "\" & "1" & ".gif")
  30.         
  31.     MsgBox "Ok"
  32. End Sub


网页图片下载.rar
2楼
eliane_lei
进来学习!
3楼
bluexuemei
Rnd()在这里起到刷新网页的作用对吗?

免责声明

有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素, 经与ExcelTip.Net站长Apolloh商议并征得其同意, 现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示, 供有需要的人士查询使用,也慰缅曾经的论坛时代。 所示各个帖子的原作者如对版权有异议, 可与本人沟通提出,或于本站点留言,我们会尽快处理。 在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一

评论列表
sitemap