再问:如何将office中的菜单的onaction与vb中的过程联系起来
我在vb6中打开一个word,并在主菜单后增加一个我自己的应用程序的菜单项 “统计”,我想将该菜单项使用onaction与我的vb程序中定义的一个子过程sum()联系起来,但运行时当我点击统计菜单时不是去执行sum过程,而是显示“由于宏安全设置,无法找到宏或宏被禁用”。但如果sum()过程定义在宏中,则正确.
请问:1.当我在主菜单后增加一个我自己的应用程序的菜单项时,能否将其与vb中的子过程(而不是与宏中定义的子过程)关联起来。
2.如果能,能否请您给一段代码,只要能实现在word中增加一个菜单项,当点击时显示个VB中的sub即可。
My code:
[vbcode]
Private Sub Command1_Click()
Set Word = CreateObject("word.application")
Word.Documents.Open ("C:\My Documents\t.doc")
Word.Visible = True
Word.Application.Caption = "test VB & word
Dim newbar As Office.CommandBar
Dim newbutton As CommandBarPopup
Dim sub_newbutton As CommandBarButton
Set newbutton = Word.CommandBars(36).Controls.Add(msoControlPopup)
newbutton.Caption = "sum"
newbutton.OnAction = "sum"
end sub
sub sum()
msgbox “hello,world”
end sub
[/vbcode]
--------------end---------------
Thank you!