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

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

问题描述

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



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



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



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



安装安装正在成功,但程序在引用14.0库时发生错误。



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



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



谢谢


解决方案

问题是您正在使用Early Binding。您必须使用延迟绑定。



在早期绑定中,您可以设置对Excel对象xx.xx库的引用,如以后绑定您不需要。



以下是



早期绑定


的示例

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

'~~>建立一个EXCEL应用程序对象
On Error Resume Next
设置oXLApp = GetObject(,Excel.Application)

'~~>如果没有找到,则创建新的实例
如果Err.Number<> 0然后
设置oXLApp =新的Excel.Application
结束如果
Err.Clear
错误GoTo 0

'~~>显示Excel
oXLApp.Visible = True

'~~>打开文件
设置oXLWb = oXLApp.Workbooks.Open(C:\Sample.xlsx)

'~~>设置相关工作表
设置oXLWs = oXLWb.Sheets(1)

'
'~~>其余的代码
'
End Sub

/ strong>

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

'~~>建立一个EXCEL应用程序对象
On Error Resume Next
设置oXLApp = GetObject(,Excel.Application)

'~~>如果没有找到,则创建新的实例
如果Err.Number<> 0然后
设置oXLApp = CreateObject(Excel.Application)
结束如果
Err.Clear
错误GoTo 0

'~~> ;显示Excel
oXLApp.Visible = True

'~~>打开文件
设置oXLWb = oXLApp.Workbooks.Open(C:\Sample.xlsx)

'~~>设置相关工作表
设置oXLWs = oXLWb.Sheets(1)

'
'~~>其余代码
'
End Sub

HERE 是一个关于Early Binding Vs Late Binding的MSDN链接。


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).

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

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

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).

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

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..

Thanks

解决方案

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

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

Here is an example of both

Early Binding

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

Late Binding

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 is an MSDN link regarding Early Binding Vs Late Binding.

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

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