Microsoft Object Library compatibility between 2007 and 2003

I have a macro in Excel 2007 that interacts with Microsoft Word. I apply the Microsoft Word 12.0 Object Library in order to access the necessary commands. However, when an Office 2003 user tries to use the macro, he gets an error. This is because Office 2003 uses the Microsoft Word 11.0 Object Library. The 12.0 library is seen as missing.

If I save the document in 2003 with the 11.0 Object library, everything works fine. Both 2003 and 2007 users are able to use the macro. But 2007 seems to automatically update the 11.0 object library to 12.0. Thus if a user saves the document in 2007 and tries to pass it back to a 2003 user, the functionality will break once again.

Is there a way to tell VBA to reference 11.0 when using 2003?


You can use late binding. Remove the reference to the Word library and use:

Dim ws As Object

Set ws=CreateObject("Word.Application")

You will need to change all built-in Word constants to values. You can find the values before you remove the library reference by typing say,

?wdDocument

Into the immediate window, or by using the Object Browser.

链接地址: http://www.djcxy.com/p/63754.html

上一篇: NormalEmail.dotm中的VBA宏

下一篇: 2007和2003之间的Microsoft Object Library兼容性