0

我有一个 VB.NET 程序,它通过以下方式将代码添加到 MS Word 中的 ThisDocument 模块:

wrdDoc.VBProject.VBComponents("ThisDocument").CodeModule.AddFromString(sCode)

它创建了以下子:

Public Sub Example_Click()
Msgbox "Working" 
End Sub

我曾经通过命令按钮的单击事件调用它,但是最好从作为 COM 加载项的一部分创建的功能区按钮调用它。

通过将以下代码添加到按钮的单击子,我已经能够在加载项中成功调用全局宏。

Globals.TestWordApp.Application.Run("Macro1")

但是,所有运行 ThisDocument 中包含的代码的尝试都失败了。

任何帮助将不胜感激。

4

1 回答 1

0

Application.Run运行宏。

宏存在于模块中,ThisDocument是一个类模块。

尝试创建一个新模块或使用现有模块而不是ThisDocument.

于 2013-10-14T12:46:16.343 回答