![](/img/trans.png)
[英]How to fix "Run time error 429: ActiveX Component Can't Create Object" Error when using Task Scheduler to run a selenium vba macro in Excel?
[英]How to fix “Execution Error 429 : ActiveX can't create object” error in VBA
下面的Excel宏应将所有.Docx转换为选定的文件夹为.Pdf
这是代码行,它为我提供了错误代码429,但几个小时前,同样的代码行正在运行。
Documents.Open (filePath & currFile) 'Error Code 429
这里是完整宏的代码
Sub ConvertDocxInDirToPDF()
Dim filePath As String
Dim currFile As String
filePath = ActiveWorkbook.Path & "\"
MsgBox filePath
currFile = Dir(filePath & "*.docx")
Do While currFile <> ""
Documents.Open (filePath & currFile) 'Error Code 429
Documents(currFile).ExportAsFixedFormat _
OutputFileName:=filePath & Left(currFile, Len(currFile) - Len(".docx")) & ".pdf", _
ExportFormat:=17
Documents(currFile).Close
currFile = Dir()
Loop
Application.ScreenUpdating = True
End Sub
是否有一种简单的方法可以使此宏工作并修复此错误。
最好的祝福。
Documents.Open
是Documents对象的一种方法,它需要“MS Word对象库”才能运行,而不是明确地引用一个单词对象:
这是什么意思? 如果选中Microsoft Word 1X.0
引用(VBE> Extras> Libraries),则下面的代码工作正常:
Sub TestMe()
Dim filePath As String
filePath = ThisWorkbook.Path & "\"
Dim currFile As String
currFile = Dir(filePath & "*.docx")
Dim wrdDoc As Object
Documents.Open filePath & currFile
End Sub
如果没有引用“MS Word对象库”,那么通过后期绑定,它仍然可以被引用到该对象。 (后期绑定是CreateObject("Word.Application")
):
Sub TestMe()
Dim filePath As String
filePath = ThisWorkbook.Path & "\"
Dim currFile As String
currFile = Dir(filePath & "*.docx")
Dim wrdApps As Object
Set wrdApps = CreateObject("Word.Application")
wrdApps.Documents.Open (filePath & currFile)
End Sub
如果需要, Documents.Open
可能会返回一个文档对象:
Sub TestMe()
Dim filePath As String
filePath = ThisWorkbook.Path & "\"
Dim currFile As String
currFile = Dir(filePath & "*.docx")
Dim wrdApps As Object
Set wrdApps = CreateObject("Word.Application")
Dim wrdDoc As Object
Set wrdDoc = wrdApps.Documents.Open(filePath & currFile)
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.