简体   繁体   English

如何修复VBA中的“执行错误429:ActiveX无法创建对象”错误

[英]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.

相关问题 使用任务计划程序在 Excel 中运行 selenium v​​ba 宏时,如何修复“运行时错误 429:ActiveX 组件无法创建对象”错误? - 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? VBA:Acrobat运行时错误429; ActiveX组件无法创建对象 - VBA: Acrobat Run time error 429; ActiveX component can't create object 使用 Excel VBA 创建 Word 应用程序:运行时错误“429”:ActiveX 组件无法创建对象 - Creating Word Application using Excel VBA: Run-time error '429': ActiveX component can't create object Excel VBA 编写内嵌 VBScript - 运行时错误“429”:ActiveX 组件无法创建对象 - Excel VBA Writing in-line VBScript - Run-time error '429': ActiveX component can't create object 创建Outlook对象会生成-运行时错误&#39;429&#39;:ActiveX组件无法创建对象 - Creating Outlook object generates - Run-time error '429': ActiveX component can't create object ActiveX 组件无法创建 object - 429 - ActiveX component can't create object - 429 从 Excel 发送邮件 - 运行时错误“429”:ActiveX 组件无法创建对象 - Sending mails from Excel - Run-time error '429': ActiveX component can't create object 脚本在调试模式下工作,但在正常运行下不工作-错误代码:429(ActiveX组件无法创建对象) - Script working in Debug Mode but not in Normal Run - Error Code: 429(ActiveX Component Can't Create Object') 将单元格复制到新工作表列时出现错误429“Activex组件无法创建对象” - Error 429 “Activex component can't create object” when copying Cells to new worksheet Column 运行时错误“ 429” activex组件无法创建对象 - run-time error '429' activex component can't create object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM