在我的程序中,我使用Microsoft Word 12.0 Object Library
自动化Word,我的系统安装了Office2007。如果我打包这个项目并交给我的客户,它会导致任何问题吗?
我的客户的计算机应该安装Office 2007以便我的程序运行吗?如果他只有Office2003会怎么样?如果出现任何问题,解决问题的方法是正确的,还是将参考值动态更改回11.0 Object Library
?
当我从“项目属性”窗口选中“我的参考”时,它会列出三个参考:
Microsoft Office 12.0 Object Library --> vpp\obj\x86\Debug\Interop.Microsoft.Office.Core.dll
Microsoft Visual Basic for Applications Extensibility 5.3 --> vpp\obj\x86\Debug\Interop.VBIDE.dll
Microsoft Word 12.0 Object Library --> vpp\obj\x86\Debug\Interop.Microsoft.Office.Interop.Word.dll
这三个dll在我的调试文件夹中。那么它可以在我客户的电脑上运行吗?
答案 0 :(得分:1)
如果您使用早期绑定,可能会在The Microsoft.Office.Interop.Word assembly version is higher than referenced中描述错误(这是C#示例,但在VB中它看起来很相似)。
关于后期绑定和早期绑定之间的差异,您可以在Binding for Office automation servers with Visual C# .NET(仍为C#eaxamples)中阅读,Using early binding and late binding in Automation描述如何在VB中执行此操作。
代码可能如下所示(来自VBA – Word – Open Word using Late Binding的示例):
Sub LaunchWord()
Dim objApp As Object
'See if Word is already running
On Error Resume Next
Set objApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'Launch a new instance of Word
Err.Clear
On Error GoTo Error_Handler
Set objApp = CreateObject("Word.Application")
objApp.Visible = True 'Make the application visible to the user (if wanted)
End If
Exit Sub
Error_Handler:
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf & "Error Number: " & _
Err.Number & vbCrLf & "Error Source: LaunchWord" & vbCrLf & "Error Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Exit Sub
End Sub
<强>加了:强>
“后期绑定”表示“没有智能感知”,所以请查看Take advantage of Intellisense when writing late bound code。