网页 图片另存为

apptestleo 2009-12-29 05:06:26
我想通过创建一个IE实例,打开某网页,然后将网页上的图片进行“图片另存为”保存为BMP格式(不能直接访问图片链接进行下载图片,另外电脑缓存文件夹也找不到这网页的图片缓存),在网上搜了很多文章。自己也参考写了一下代码。发现vba 不支持 Clipboard.GetData的使用,不知道能否用其它方式实现呢?例如api 的OleCreatePictureIndirect可以吗?请大家帮忙,谢谢。

Dim ie As Object
dim url As String
url="http://xxxxxxxx"
Set ie = CreateObject("InternetExplorer.application")
ie.Navigate url
Do While ie.busy Or ie.ReadyState <> 4
DoEvents
Loop

Dim CtrlRange As Object
Set CtrlRange = ie.Document.body.createControlRange
CtrlRange.Add ie.Document.images(0)

Dim Pic As StdPicture
Set Pic = Clipboard.GetData '运行时候这里出错,提示“要求对象”
SavePicture Pic, ThisWorkbook.path & "\img.bmp"
MsgBox "完成"
...全文
659 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2009-12-30
  • 打赏
  • 举报
回复
改用AutoHotKey软件试试
cbm6666 2009-12-30
  • 打赏
  • 举报
回复
Dim ie As Object
Dim pic As StdPicture
Private Sub Command1_Click()
Set ie = CreateObject("INTERNETEXPLORER.APPLICATION")
ie.Visible = True
ie.Navigate "http://topic.csdn.net/u/20091229/17/ad04b74c-cdbe-4b9a-bb96-ab566f193821.html?30332"
End Sub

Private Sub Command2_Click()
Dim CtrlRange
Dim x
For Each x In ie.Document.All
If UCase(x.tagName) = "IMG" Then
Clipboard.Clear
Set CtrlRange = ie.Document.body.createControlRange()
CtrlRange.Add (x)
CtrlRange.execCommand ("Copy")
Set pic = Clipboard.GetData
SavePicture pic, "c:\Img.bmp"
Exit For
End If
Next
End Sub

舉杯邀明月 2009-12-29
  • 打赏
  • 举报
回复
CtrlRange.Add ie.Document.images(0)

能把图像数据放入剪贴板?
apptestleo 2009-12-29
  • 打赏
  • 举报
回复
顶一下。

2,462

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧