我想通过创建一个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
LoopDim 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 "完成"

解决方案 »

  1.   

    CtrlRange.Add ie.Document.images(0)能把图像数据放入剪贴板?
      

  2.   

    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 SubPrivate 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