i'm getting captcha image from webpage and inserting it to excel cell, then manually proceding this captcha by writing it to inputbox in excel, then excel pass this captcha text back to opened IE window.
So every element of code works fine, but i'm getting one version of captcha image on opened IE window and diffrent one inserted to excel.
Why is that ? It looks like diffrent instance of IE is opened and diffrent instance of IE was used for inserting captcha image to excel.
Sub Get_captcha()
Dim ie As New InternetExplorer
ie.Visible = True
ie.Navigate ActiveCell
Do
DoEvents
Loop Until (ie.ReadyState = 4 And Not ie.Busy)
Dim doc As HTMLDocument
Set doc = ie.Document
Dim MyInput As String
captcha = doc.getElementById("MainContent_ctrlCaptcha").getAttribute("src")
ActiveCell.Offset(0, 2).Value = captcha
With ActiveSheet.Pictures
.Insert (doc.getElementById("MainContent_ctrlCaptcha").getAttribute("src"))
End With
End Sub
Diffrent approach with screen capturing
Sub Get_captcha()
Application.DisplayAlerts = False: Application.ScreenUpdating = False: Application.EnableEvents = False
On Error GoTo Cleanup
Dim clipboard As MSForms.DataObject
Set clipboard = New MSForms.DataObject
clipboard.Clear
Dim ie As New InternetExplorer
ie.Visible = True
ie.Navigate ActiveCell.Value
Do
DoEvents
Loop Until ie.ReadyState = READYSTATE_COMPLETE
Dim doc As HTMLDocument
Set doc = ie.Document
Dim MyInput As String
captcha = doc.getElementById("MainContent_ctrlCaptcha").getAttribute("src")
ActiveCell.Offset(0, 2).Value = captcha
Sleep (500)
Application.SendKeys "(%{1068})"
Sleep (500)
ie.Quit
Dim shp As Shape
ActiveSheet.Paste Destination:=ActiveSheet.Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(-12, -8)), link:=False
With ActiveSheet
Set shp = .Shapes(.Shapes.Count)
shp.PictureFormat.CropRight = 500
shp.PictureFormat.CropBottom = 330
shp.PictureFormat.CropTop = 150
shp.PictureFormat.CropLeft = 278
End With
ActiveCell.Offset(1).Select
Cleanup:
Application.DisplayAlerts = True: Application.ScreenUpdating = True: Application.EnableEvents = True
End Sub