VB6程序无法打开未注册自动化错误库的Excel 2007 [英] VB6 program fails opening Excel 2007 with Automation Error Library not registered

查看:214
本文介绍了VB6程序无法打开未注册自动化错误库的Excel 2007的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行Office 2010 32位的Windows 7 32位计算机上创建了此VB6程序.在具有Office 2013 32位的Windows 8 64位计算机上对其进行了测试,它可以正常工作.在装有Windows 7 64位和Office 2007(仅32位)的计算机上,它在以下代码段中引发错误.

实际错误消息:

运行时错误–2147319779(8002801d)自动化错误,库没有 已注册

VB6代码:

If (excel_app Is Nothing) Then
    Set excel_app = CreateObject("Excel.Application")
Else
    Set excel_app = GetObject(, "Excel.Application")
End If

excel_app.Visible = True
excel_version = excel_app.Application.Version
Set wBook = excel_app.Workbooks.Open(directory_path & "\templates\book1.xlsm")

因此,当我打开book1时会引发错误.它实际上确实打开了它,并在Workbook_Open()上运行了一个宏,这运行正常.完成并处理程序返回到VB6程序后,将引发错误.

以下是项目参考:

有人遇到过这个问题吗?

我在这里显然做错了,我的错误处理程序正在抛出错误.

我确实尝试了另一件事,并且将其删除"Set wBook =",并且没有引发错误.从那时起,我就放了"Set wBook =",因为我确实需要在代码中进一步添加它.

    Dim wBook As Workbook
    Dim excel_app As Object

    On Error GoTo trialhandler

    If (excel_app Is Nothing) Then
        Set excel_app = CreateObject("Excel.Application")
    Else
        Set excel_app = GetObject(, "Excel.Application")
    End If

    excel_app.Visible = True
    excel_version = excel_app.Application.Version
    Set wBook = excel_app.Workbooks.Open(directory_path & "\templates\book1.xlsm")

    MsgBox ("Exiting")
    Exit Sub
trialhandler:

    Dim source_string As String
    source_string = excel_app.Source 'Error here
    MsgBox ("My Error 1:" & source_string)
    excel_app.Err
    MsgBox ("My Error 2:" & excel_app.Err.Number & "  " & excel_app.Err.Description)

    Exit Sub

我以前在此计算机上安装过Office 2013,然后将其卸载并放置了2007,这会产生什么影响吗?还是我已经参考Excel 2010创建了该程序,现在又想在Office 2007上运行它呢?尽管它可以在2013年的其他机器上使用.

它已经通过了初始错误,之后又引发了完全相同的错误.这部分导入了一个mdb表.一定还有一些早期的约束力

    With wBook.Worksheets("Seal Register").ListObjects.Add(SourceType:=0, Source:=Array( _
        "OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data Source=" & db_full_path & ";" _
        , _
        "Mode=ReadWrite;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";" _
        , _
        "Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;" _
        , _
        "Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;" _
        , _
        "Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;" _
        , _
        "Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False"), _
        Destination:=Range("A" & row_number)).QueryTable
        .MaintainConnection = False
        .CommandType = xlCmdTable
        .CommandText = Array(db_table_name)
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = 1
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .SourceDataFile = db_full_path
        .ListObject.DisplayName = "Table_" & db_table_name
        .Refresh BackgroundQuery:=False
    End With

解决方案

没有理由认为这是vb错误.

返回或设置最初产生错误的对象或应用程序的名称.

object.Source [= stringexpression]

参数 目的 始终是Err对象.

stringexpression 一个字符串表达式,表示生成错误的应用程序.

备注 Source属性指定一个字符串表达式,该表达式通常是导致错误的对象的类名或编程ID.当您的代码无法处理在访问的对象中生成的错误时,请使用Source为用户提供信息.例如,如果您访问Microsoft Excel并生成零除错误,Microsoft Excel会将Err.Number设置为该错误的错误代码,并将Source设置为Excel.Application.请注意,如果错误是在另一个由Microsoft Excel调用的对象中生成的,则Excel会拦截该错误并将Err.Number设置为其自己的代码,以将其除以零.但是,它将其他Err对象(包括Source)保留为生成错误的对象所设置的对象.

源始终包含最初生成错误的对象的名称-您的代码可以根据您访问的对象的错误文档尝试处理该错误.如果错误处理程序失败,则可以使用Err对象信息向用户描述错误,使用Source和另一个Err通知用户最初是哪个对象导致了错误,错误的描述等.

从自动化Microsoft Office 97和Microsoft Office 2000开始 洛瑞·特纳(Lori Turner) 微软公司

2000年3月

问题: 我的自动化客户端可以与我的应用程序的Office 97版本一起正常工作.但是,我重新构建了项目,它在Office 2000上可以正常运行,但在Office 97上却失败.这可能是什么问题?

Office的新版本包括新功能并增强了一些现有功能.为了向客户提供对这些新功能和增强功能的编程访问,必须更新对象模型.由于进行了此更新,因此与Office 97相比,Office 2000中的方法可能具有更多的参数.

现有方法的新参数通常是可选的.如果您使用后期绑定到Office Automation服务器,则您的代码应能与Office 97或Office 2000一起成功使用.但是,如果您使用早期绑定,则在以下情况下97和2000类型库之间的差异可能会导致问题:

如果在Visual Basic中创建自动化客户端并引用Office 2000类型库,则在调用Office 97服务器时,如果调用已更改的方法或属性,则代码可能会失败.

如果您创建MFC自动化客户端并使用ClassWizard来包装Office 2000类型库中的类,则在使用Office 97服务器时,如果调用已更改的方法或属性,则代码可能会失败. 为避免此问题,应针对要支持的最低版本的Office服务器开发Automation客户端.为了保持与多个版本的Office的兼容性的最佳结果,应该使用后期绑定.但是,如果选择使用早期绑定,请绑定到要支持的Office服务器最早版本的类型库.为了说明,如果您要使用Visual Basic编写自动化客户端,并希望该客户端与Excel 97和Excel 2000一起使用,则应在Visual Basic项目中引用Excel 97类型库.同样,如果要使用MFC编写自动化客户端,则应使用ClassWizard包装Excel 97类型库.

有关更多信息,请参见Microsoft知识库中的以下文章:

Q224925信息:Office 2000的类型库已更改

I created this VB6 program on my Windows 7 32bit machine with Office 2010 32bit, which runs fine. Tested it on a Windows 8 64 bit machine with Office 2013 32bit, it works. On one machine with, Windows 7 64 bit and Office 2007(32 bit only) it throws an error during the following piece of code.

The actual error message:

Run-time Error –2147319779 (8002801d) Automation error, Library not registered

VB6 Code:

If (excel_app Is Nothing) Then
    Set excel_app = CreateObject("Excel.Application")
Else
    Set excel_app = GetObject(, "Excel.Application")
End If

excel_app.Visible = True
excel_version = excel_app.Application.Version
Set wBook = excel_app.Workbooks.Open(directory_path & "\templates\book1.xlsm")

So it is throwing the error when I open book1. It actual does open it and it has a macro run on Workbook_Open(), this runs right through seemly fine. After it finishes and processing of the program returns to the VB6 program it throws the error.

Here are the project references:

Has anyone come across this and what would be the fix?

[EDIT]

I am obviously doing something wrong here my error handler is throwing an error.

I did try one other thing and that was removed "Set wBook = " and it didn't throw an error. I have placed "Set wBook = " back since then, as I do need it further on in my code.

    Dim wBook As Workbook
    Dim excel_app As Object

    On Error GoTo trialhandler

    If (excel_app Is Nothing) Then
        Set excel_app = CreateObject("Excel.Application")
    Else
        Set excel_app = GetObject(, "Excel.Application")
    End If

    excel_app.Visible = True
    excel_version = excel_app.Application.Version
    Set wBook = excel_app.Workbooks.Open(directory_path & "\templates\book1.xlsm")

    MsgBox ("Exiting")
    Exit Sub
trialhandler:

    Dim source_string As String
    source_string = excel_app.Source 'Error here
    MsgBox ("My Error 1:" & source_string)
    excel_app.Err
    MsgBox ("My Error 2:" & excel_app.Err.Number & "  " & excel_app.Err.Description)

    Exit Sub

I had Office 2013 installed on this previously, then uninstalled it and placed 2007 on it, could this have any impact? Or the fact that I have created this program with reference to Excel 2010 and now I'm trying to run it against Office 2007? Though it works on the other machine with 2013. Grasping at straws here.

[EDIT 2]

It has passed the initial error to throw exactly the same error later on. This piece imports an mdb table. There must be some early binding left over

    With wBook.Worksheets("Seal Register").ListObjects.Add(SourceType:=0, Source:=Array( _
        "OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data Source=" & db_full_path & ";" _
        , _
        "Mode=ReadWrite;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";" _
        , _
        "Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;" _
        , _
        "Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;" _
        , _
        "Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;" _
        , _
        "Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False"), _
        Destination:=Range("A" & row_number)).QueryTable
        .MaintainConnection = False
        .CommandType = xlCmdTable
        .CommandText = Array(db_table_name)
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = 1
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .SourceDataFile = db_full_path
        .ListObject.DisplayName = "Table_" & db_table_name
        .Refresh BackgroundQuery:=False
    End With

解决方案

There no reason to think this is a vb error.

Returns or sets the name of the object or application that originally generated the error.

object.Source [= stringexpression]

Arguments object Always the Err object.

stringexpression A string expression representing the application that generated the error.

Remarks The Source property specifies a string expression that is usually the class name or programmatic ID of the object that caused the error. Use Source to provide your users with information when your code is unable to handle an error generated in an accessed object. For example, if you access Microsoft Excel and it generates a Division by zero error, Microsoft Excel sets Err.Number to its error code for that error and sets Source to Excel.Application. Note that if the error is generated in another object called by Microsoft Excel, Excel intercepts the error and sets Err.Number to its own code for Division by zero. However, it leaves the other Err object (including Source) as set by the object that generated the error.

Source always contains the name of the object that originally generated the error — your code can try to handle the error according to the error documentation of the object you accessed. If your error handler fails, you can use the Err object information to describe the error to your user, using Source and the other Err to inform the user which object originally caused the error, its description of the error, and so forth.

From Automating Microsoft Office 97 and Microsoft Office 2000 Lori Turner Microsoft Corporation

March 2000

PROBLEM: My Automation client worked fine with the Office 97 version of my application. However, I rebuilt my project and it works fine with Office 2000 but now fails with Office 97. What could be wrong?

New versions of Office include new features and enhance some of the existing ones. To provide clients with programmatic access to these new and enhanced features, the object models must be updated. Because of this update, a method may have more arguments for Office 2000 than it did with Office 97.

The new arguments to existing methods are usually optional. If you use late binding to the Office Automation server, your code should work successfully with either Office 97 or Office 2000. However, if you use early binding, the differences between the 97 and 2000 type libraries could cause you problems in the following situations:

If you create an Automation client in Visual Basic and reference the Office 2000 type library, your code might fail when using an Office 97 server if you call a method or property that has changed.

If you create an MFC Automation client and use the ClassWizard to wrap classes from the Office 2000 type library, your code might fail when using an Office 97 server if you call a method or property that has changed. To avoid this problem, you should develop your Automation client against the lowest version of the Office server you intend to support. For the best results in maintaining compatibility with multiple versions of Office, you should use late binding. However, if you choose to use early binding, bind to the type library for the earliest version of the Office server you want to support. To illustrate, if you are writing an Automation client with Visual Basic and want that client to work with Excel 97 and Excel 2000, you should reference the Excel 97 type library in your Visual Basic project. Likewise, if you are writing an Automation client using MFC, you should use the ClassWizard to wrap the Excel 97 type library.

For more information, please see the following article in the Microsoft Knowledge Base:

Q224925 INFO: Type Libraries for Office 2000 Have Changed

这篇关于VB6程序无法打开未注册自动化错误库的Excel 2007的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆