简体   繁体   English

使用 VBA 从网页复制特定图像并粘贴到 Excel 中

[英]Copy specific image from webpage and paste into Excel using VBA

I'm trying to take a character string from a cell, copy it into a free QR code generator (ex| http://goqr.me/ ), and bring the resulting image back into my spreadsheet.我正在尝试从单元格中获取字符串,将其复制到免费的二维码生成器(例如 | http://goqr.me/ ),然后将生成的图像带回我的电子表格。 (I like this generator because you don't need to click "submit" - it updates the image as the text is entered. Assuming/hoping that feature makes this easier) (我喜欢这个生成器,因为你不需要点击“提交”——它会在输入文本时更新图像。假设/希望这个功能能让这更容易)

I'm trying to avoid the installation of new barcode fonts and the purchasing of barcode specific packages.我试图避免安装新的条形码字体和购买特定于条形码的包。

Using the below code, I can get the browser to open and enter the desired text.使用下面的代码,我可以让浏览器打开并输入所需的文本。 I need a way to get the image back into my spreadsheet now.我现在需要一种方法将图像恢复到我的电子表格中。 The code I'm using currently just returns "[object]" (as text) in cell C1.我当前使用的代码仅在单元格 C1 中返回“[object]”(作为文本)。

How can I use VBA to get this image onto my clipboard?如何使用 VBA 将此图像放到剪贴板上?

    Public ieApp As Object

Sub Barcode()

  Dim ieDoc As Object
  Dim InputBox As Object
  Dim qrBoxImage as Object

  barcodeTerm = Range("B1").Value

    If TypeName(ieApp) = "Object" Or TypeName(ieApp) = "Nothing" Then
        Set ieApp = CreateObject("InternetExplorer.Application")
        ieApp.Navigate ("http://goqr.me/")

    End If

      While ieApp.ReadyState <> 4
        DoEvents
      Wend

      ieApp.Visible = True

      Set ieDoc = ieApp.Document

        Set InputBox = ieDoc.getElementsByName("text")
        Set qrBoxImage = ieDoc.getElementByID("qrcode-preview-image")


        InputBox.Item(0).Value = barcodeTerm
        Range("C1").Value = qrBoxImage

      Set ieDoc = Nothing

End Sub

You can follow the steps detailed over here:您可以按照此处详细说明的步骤操作:

http://social.technet.microsoft.com/wiki/contents/articles/23860.print-screen-to-an-image-using-access-vba.aspx http://social.technet.microsoft.com/wiki/contents/articles/23860.print-screen-to-an-image-using-access-vba.aspx

Although the example is used in Access, it's still VBA code so it still should work in Excel尽管该示例在 Access 中使用,但它仍然是 VBA 代码,因此它仍然应该在 Excel 中工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM