简体   繁体   中英

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. (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.

How can I use VBA to get this image onto my clipboard?

    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

Although the example is used in Access, it's still VBA code so it still should work in Excel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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