下面是脚本部件文件的代码:- <package>
- <?component error="true"?>
- <component id="JS">
- <registration
- progid="JSComponent.Person"
- description="Person Object">
- </registration>
- <public>
- <property name="Name" />
- <property name="Age" />
- <method name="sayHello" />
- <method name="init">
- <parameter name="name" />
- <parameter name="age" />
- </method>
- </public>
- <script language="JScript">
- var Name,Age;
- function init(name,age){
- Name=name;
- Age=age;
- }
- function sayHello(){
- return "hello, world";
- }
- </script>
- </component>
- </package>
复制代码 现在脚本部件已经注册成功,但生成TLB文件也成功了,但是在VBA中一调用EXCEL就崩溃,求解???
如下是VBA中的调用代码【此前已经引用了生成的TLB文件,在VB对象浏览器中可以查看到类型库成员】- Sub Test()
- Dim objP As ScriptletTypeLib.JS
- CallByName objP, "init", VbMethod, "Tom", 32
- Out.Output objP.Name
- Out.Output objP.sayHello()
- End Sub
复制代码
|