自动上传图片文件到免费的在线OCR资源

我试图上传一个.jpg文件到一个免费的在线OCR网站。 我为这个项目使用Excel VBA:

Sub getOcrText() Dim ocrAddress As String: ocrAddress = "http://www.free-online-ocr.com" Dim picFile As String: picFile = "C:\Users\310217955\Documents\pdfdown\test.jpg" Dim elementCollection As Variant Dim IE As New InternetExplorerMedium With IE .Visible = True .Navigate (ocrAddress) Do While IE.Busy: DoEvents: Loop Set elementCollection = IE.document.getElementsByName("fileUpload") End With IE.Quit Set IE = Nothing End Sub 

然而,当我运行代码,看我是否得到对象elementCollection我得到一个运行时错误,自动化错误,未指定的错误 ,代码成功导航到所需的网页。

在这里输入图像说明

我如何克服这个错误?

你需要改变几行。

首先这一个:

 Dim IE As Object: Set IE = CreateObject("InternetExplorer.Application") 

第二个问题

IE.Busy不是一个足够的testing。 请改为:

 Do While (IE.Busy Or IE.READYSTATE <> 4): DoEvents: Loop