VB 6 程序中的 MS Office 14.0 对象库引用 [英] MS Office 14.0 object library references in VB 6 program

查看:18
本文介绍了VB 6 程序中的 MS Office 14.0 对象库引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 VB 6 程序代码是指 14.0 对象库,它被编译和执行..使用新代码正常工作(访问 14.0 库).

My VB 6 program code is referring to 14.0 object library, it is compiled and executed..working fine with the new code (accessing 14.0 libraries).

在我的开发系统中,安装了 Microsoft Office 2010(14.0 库),我的新代码已在其中编译并正常工作..

In my development system, Microsoft Office 2010 is installed (14.0 library), where my new code is compiled and working fine..

我正在使用这些库将文档转换为 pdf.

I'm using these libraries to convert document to pdf.

我正在尝试安装同一 VB 6 程序的设置并在不存在 14.0 库的不同机器上运行,因为该机器上安装了 MS Office 2000(12.0 库).

I'm trying to install the setup of the same VB 6 program and run in different machine, where 14.0 libraries are not present, because MS Office 2000 is installed on that machine (12.0 libraries).

安装程序安装成功,但程序在引用 14.0 库时抛出错误.

Setup installation is getting successful, but the program is throwing an error while referencing 14.0 libraries.

现在,我需要这方面的帮助,即,如何在新机器上安装 14.0 对象库,以便程序运行时有引用.

Now, I need a help in this regard, that, How can I install the 14.0 object libraries on the new machine, so that the references will be there for the program to run.

或者,请给我建议任何其他方法来完成它..

Or, please suggest me any other approaches to get it done..

谢谢

推荐答案

问题是你使用的是 Early Binding.您必须使用后期绑定.

The problem is that you are using Early Binding. You have to use Late Binding.

在早期绑定中,您设置对 Excel 对象 xx.xx 库的引用,而在后期绑定中您没有.

In Early Binding, you set a reference to the Excel Object xx.xx Library where as in late Binding you do not.

以下是两者的示例

早期绑定

Sub EarlyBindingEx()
    Dim oXLApp As Excel.Application
    Dim oXLWb As Excel.Workbook
    Dim oXLWs As Excel.Worksheet

    '~~> Establish an EXCEL application object
    On Error Resume Next
    Set oXLApp = GetObject(, "Excel.Application")

    '~~> If not found then create new instance
    If Err.Number <> 0 Then
        Set oXLApp = New Excel.Application
    End If
    Err.Clear
    On Error GoTo 0

    '~~> Show Excel
    oXLApp.Visible = True

    '~~> Open files
    Set oXLWb = oXLApp.Workbooks.Open("C:Sample.xlsx")

    '~~> Set the relevant worksheet
    Set oXLWs = oXLWb.Sheets(1)

    '
    '~~> Rest of your code
    '
End Sub

后期装订

Sub LateBindingEx()
    Dim oXLApp As Object
    Dim oXLWb As Object, oXLWs As Object

    '~~> Establish an EXCEL application object
    On Error Resume Next
    Set oXLApp = GetObject(, "Excel.Application")

    '~~> If not found then create new instance
    If Err.Number <> 0 Then
        Set oXLApp = CreateObject("Excel.Application")
    End If
    Err.Clear
    On Error GoTo 0

    '~~> Show Excel
    oXLApp.Visible = True

    '~~> Open files
    Set oXLWb = oXLApp.Workbooks.Open("C:Sample.xlsx")

    '~~> Set the relevant worksheet
    Set oXLWs = oXLWb.Sheets(1)

    '
    '~~> Rest of your code
    '
End Sub

HERE 是有关 Early Binding Vs Late Binding 的 MSDN 链接.

HERE is an MSDN link regarding Early Binding Vs Late Binding.

这篇关于VB 6 程序中的 MS Office 14.0 对象库引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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