![](/img/trans.png)
[英]Creating Word Application using Excel VBA: Run-time error '429': ActiveX component can't create object
[英]VBA: Acrobat Run time error 429; ActiveX component can't create object
我有以下代碼從Excel VBA中的PDF文件中讀取內容:
'Note: A Reference to the Adobe Library must be set in Tools|References!
Dim AcroApp As CAcroApp, AcroAVDoc As CAcroAVDoc, AcroPDDoc As CAcroPDDoc
Dim AcroHiliteList As CAcroHiliteList, AcroTextSelect As CAcroPDTextSelect
Dim PageNumber, PageContent, Content, i, j
Set AcroApp = CreateObject("AcroExch.App")
Set AcroAVDoc = CreateObject("AcroExch.AVDoc")
If AcroAVDoc.Open(strFileName, vbNull) <> True Then Exit Function
' The following While-Wend loop shouldn't be necessary but timing issues may occur.
While AcroAVDoc Is Nothing
Set AcroAVDoc = AcroApp.GetActiveDoc
Wend
Set AcroPDDoc = AcroAVDoc.GetPDDoc
For i = 0 To AcroPDDoc.GetNumPages - 1
Set PageNumber = AcroPDDoc.AcquirePage(i)
Set PageContent = CreateObject("AcroExch.HiliteList")
If PageContent.Add(0, 9000) <> True Then Exit Function
Set AcroTextSelect = PageNumber.CreatePageHilite(PageContent)
' The next line is needed to avoid errors with protected PDFs that can't be read
On Error Resume Next
For j = 0 To AcroTextSelect.GetNumText - 1
Content = Content & AcroTextSelect.GetText(j)
Next j
Next i
ReadAcrobatDocument = Content
AcroAVDoc.Close True
AcroApp.Exit
Set AcroAVDoc = Nothing: Set AcroApp = Nothing
End Function
Sub demo()
Dim str As String
str = ReadAcrobatDocument("C:\Desktop\asdf.pdf")
End Sub
但是,我得到運行時429錯誤
Set AcroApp = CreateObject("AcroExch.App")
怎么了? 我有Adobe Reader X,我檢查的參考文獻是:
Acrobat Access 3.0類型庫AcroBrokerLib AcroIEHelper 1.0類型庫AcroIEHelperShim 1.0類型庫Adobe Acrobat瀏覽器控件類型庫1.0 Adobe Acrobat 10.0類型庫Adobe Reader文件預覽類型庫
從Google搜索查詢的第一個結果:
createobject acroexch.app錯誤429
你不能用Adobe Reader做到這一點,你需要Adobe Acrobat:
此OLE接口可用於Adobe Acrobat,而不是Adobe Reader。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.