再问:如何将office中的菜单的onaction与vb中的过程联系起来

visual 2000-07-03 11:50:00
我在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!
...全文
81 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧