我正在尝试将.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
的对象时,我收到运行时错误,自动化错误,未指定的错误,代码成功导航到所需的网页。
如何克服此错误?
答案 0 :(得分:4)
您需要更改几行。
首先是这个:
Dim IE As Object: Set IE = CreateObject("InternetExplorer.Application")
第二个问题......
IE.Busy
不是一个充分的测试。将该行改为:
Do While (IE.Busy Or IE.READYSTATE <> 4): DoEvents: Loop