开发者

Calling VBA-Macros with user-defined Types from C#?

开发者 https://www.devze.com 2023-02-06 20:16 出处:网络
I\'ve got a Word Document with a VBA Module that contains user defined Types (public Type XXX) and some public subs that take this Type as arguments. Is it possible to call these subs from C# via Appl

I've got a Word Document with a VBA Module that contains user defined Types (public Type XXX) and some public subs that take this Type as arguments. Is it possible to call these subs from C# via Application's Run()?

Greeting开发者_StackOverflow中文版s, Steven


I don't know if you have the flexibility to do this, but here's how I solved this.

  1. Create another assembly (I called mine "xx.Common")
  2. Add some structs in there, make them COM-visible
  3. Reference that assembly from both the VBA and C# projects
  4. Add a new VBA sub with those structs as arguments

You can now pass in structured, user-defined data. If you generalize this idea, you can use any COM-visible type (i.e. not just structs). As long as both projects reference an assembly that defines these types, you should be ok.

0

精彩评论

暂无评论...
验证码 换一张
取 消