【问题标题】:run-time error '429' activex component can't create object运行时错误“429”activex 组件无法创建对象
【发布时间】:2011-02-08 15:12:29
【问题描述】:

我创建了一个简单的应用程序 .net 类,可将 Excel 电子表格转换为 pdf 文件。然后我得到一个 Excel 2007 应用程序来调用这个在我的开发机器上运行良好的 dll。

但是,当我将它部署到同时具有 .net 框架和 Excel 2007 的 Vista 机器上时,我收到此错误:

run-time error '429' activex component can't create object

即使我是机器上的管理员,我似乎也无法将签名的 .net dll 放入 GAC。

有人可以帮我解决这个问题吗?

这就是我从 Excel 2007 调用 .net tlb 文件的方式。

Sub TestSub()<br>
 &nbsp;Dim printLibraryTest As PrintLibrary.Print<br>
 &nbsp;Set printLibraryTest = New PrintLibrary.Print <br>
 &nbsp; printLibraryTest.ConvertExcelToPdf <br>
End Sub <br>

这是下面的 .net 库。

using System;<br>
using System.Collections.Generic;<br>
using System.Runtime.InteropServices;<br>
using System.Text;<br>
using Microsoft.Office.Interop.Excel;<br><br>

namespace PrintLibrary<br>
{<br>
    [ClassInterface(ClassInterfaceType.None)]<br>
    [Guid("3d0f04d2-9123-48e0-b12f-6c276ff2281b")]<br>
    [ProgId("PrintLibrary.Test")]<br>
    public class Print<br>
    {      <br>
        public void ConvertExcelToPdf(string inputFile,string outputFile)    <br>
        {    <br>
          &nbsp;&nbsp;  ApplicationClass excelApplication = new ApplicationClass();    <br>
          &nbsp;&nbsp;   Workbook excelWorkBook = null;    <br>
          &nbsp;&nbsp;  string paramSourceBookPath = inputFile;    <br>
          &nbsp;&nbsp;   object paramMissing = Type.Missing;    <br>

          string paramExportFilePath = outputFile;
          XlFixedFormatType paramExportFormat = XlFixedFormatType.xlTypePDF;
          XlFixedFormatQuality paramExportQuality =
          XlFixedFormatQuality.xlQualityStandard;
          bool paramOpenAfterPublish = false;
          bool paramIncludeDocProps = true;
          bool paramIgnorePrintAreas = true;
          object paramFromPage = Type.Missing;
          object paramToPage = Type.Missing;


            try
            {
                // Open the source workbook.
                excelWorkBook = excelApplication.Workbooks.Open(paramSourceBookPath,
                paramMissing, paramMissing, paramMissing, paramMissing,
                paramMissing, paramMissing, paramMissing, paramMissing,
                paramMissing, paramMissing, paramMissing, paramMissing,
                paramMissing, paramMissing);

                // Save it in the target format.
                if (excelWorkBook != null)
                    excelWorkBook.ExportAsFixedFormat(paramExportFormat,
                    paramExportFilePath, paramExportQuality,
                    paramIncludeDocProps, paramIgnorePrintAreas, paramFromPage,
                    paramToPage, paramOpenAfterPublish,
                    paramMissing);
            }
            catch (Exception ex)
            {
                // Respond to the error.
            }

终于

            {
                // Close the workbook object.
                if (excelWorkBook != null)
                {
                    excelWorkBook.Close(false, paramMissing, paramMissing);
                    excelWorkBook = null;
                }

                // Quit Excel and release the ApplicationClass object.
                if (excelApplication != null)
                {
                    excelApplication.Quit();
                    excelApplication = null;
                }

                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }  
        }
    }
}

【问题讨论】:

  • 我假设您的“PrintLibrary.dll”是使用 .NET 构建的?它有任何 COM 可见的类或接口吗?如果没有,则无需注册。如果是这样,我假设您正在使用 RegAsm 注册它,或者您是否(错误地)尝试使用 RegSvr32?当您运行代码并得到“运行时错误'429'activex组件无法创建对象”时,它是哪一行代码? (也就是说,它试图创建什么对象——你确定它来自你的'PrintLibrary.dll吗?)
  • 嗨,迈克,感谢您回复我。我创建了对 Visual Studio 创建的 .net tlb 库的引用。它似乎打破了这条线...... printLibraryTest.ConvertExcelToPdf。即使 Visual Studio 创建了一个 tlb 库,我还需要使用 Regasm 吗?我也在使用ClassInterface(ClassInterfaceType.None,所以没有为类生成类接口。

标签: c# .net excel vba excel-2007


【解决方案1】:

一年后...

这可能是由于与此相同的原因:http://support.microsoft.com/kb/313984/en-us

因为目标计算机缺少应用程序中使用的控件对象的许可证信息而发生错误 [...] 这将生成一个包含正确版本的 Winsock 控件的安装包。但是,除非将控件的实例放在窗体上,否则控件的许可证密钥不会编译到应用程序中。当您尝试在运行时实例化对象时,应用程序无法提供许可证密钥,代码将失败。例如,以下代码在设计时可以正常运行,但在没有安装 Visual Basic 的计算机上运行时会失败。

这里似乎与您的情况有关:

  • 相同的错误号和消息
  • 同时发生:当您部署到非开发机器时

解决方法似乎是将控件放在窗体上。


也请查看这篇文章:Run-time error '429'

【讨论】:

    【解决方案2】:

    执行时 Excel 2007 VB 脚本运行时错误 429:

    Set objFSO = CreateObject("Scripting.FileSystemObject").
    

    解决方案:

    1. 检查它指向的“我的文档”位置。
    2. 检查 Excel 选项保存位置。
    3. 运行“regsvr32 scrrun.dll”。

    参考资料:

    【讨论】:

      猜你喜欢
      • 2013-04-13
      • 2015-04-24
      • 2016-04-24
      • 2021-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      相关资源
      最近更新 更多