[英]How to fix “Execution Error 429 : ActiveX can't create object” error in VBA
This Excel macro below should convert all .Docx into the selected folder to .Pdf 下面的Excel宏应将所有.Docx转换为选定的文件夹为.Pdf
Here is the code line which provide me the error Code 429, But several hours ago this same line of code was working. 这是代码行,它为我提供了错误代码429,但几个小时前,同样的代码行正在运行。
Documents.Open (filePath & currFile) 'Error Code 429
Here the full macro's code 这里是完整宏的代码
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
Is there a simple way to make this macro working and to fix this error. 是否有一种简单的方法可以使此宏工作并修复此错误。
Best regards. 最好的祝福。
Documents.Open
is a method of the Documents object, which needs the "MS Word Object Library" to function, without being referred to a word object explicitly: Documents.Open
是Documents对象的一种方法,它需要“MS Word对象库”才能运行,而不是明确地引用一个单词对象:
What does this mean? 这是什么意思? If the Microsoft Word 1X.0
reference is checked (VBE>Extras>Libraries), then the code below works quite ok: 如果选中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
If the "MS Word Object Library" is not referred, then with late binding it still could be referred to the object. 如果没有引用“MS Word对象库”,那么通过后期绑定,它仍然可以被引用到该对象。 (Late binding is CreateObject("Word.Application")
): (后期绑定是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
If needed, Documents.Open
may return a document object: 如果需要, 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.