0

我正在开发一个从 Excel VBA 使用的 COM 服务器。当我更新服务器(编辑代码、注销、重新注册)时,Excel 似乎继续使用 COM 服务器的原始版本,而不是更新版本。我发现让它使用更新版本的唯一方法是关闭并重新打开 Excel,这有点烦人。有没有办法强制 Excel 使用新注册的版本(可能是某种“清除缓存”选项)?

更多细节:

该服务器正在 Python 中使用 win32com 开发。

在 VBA 中,我正在做类似的事情:

set obj=CreateObject("Foo.Bar")
obj.baz()

Foo.Bar 是我在注册表中注册的 COM 服务器。

如果我取消注册服务器然后运行 ​​VBA 代码,我会从 VBA 收到“无法创建对象”错误,因此它必须意识到正在发生某些事情。但是一旦我重新注册它就会选择旧版本。

任何提示表示赞赏!

谢谢,

安迪

4

2 回答 2

2

我找到了解决我的问题的方法——一般的想法是进行设置,以便主 COM 服务器类在调用时动态加载其余的 COM 服务器代码。因此,在 Python 中,我创建了一个类似于以下内容的 COM 服务器类:

import main_code

class COMInterface:
    _public_methods_ = [ 'method1' ]
    _reg_progid_ = "My.Test"
    _reg_clsid_ = "{D6AA2A12-A5CE-4B6C-8603-7952B711728B}"

    def methods(self, input1,input2,input3):
        # force python to reload the code that does the actual work 
        reload(main_code)
        return main_code.Runner().go(input1,input2,input3)

The main_code module contains the code that does the actual work and is reloaded each time the COM method is called. This works as long as the inputs don't change. There will presumably be a runtime penalty for this, so might want to remove the reload for the final version, but it works for development purposes.

于 2010-03-01T07:07:42.827 回答
0

只是一个建议,您是否尝试过卸载对象?也许在你的 excel spredsheat 中创建一个按钮来强制卸载对象。

我希望它有帮助

于 2010-02-26T08:36:30.960 回答