您的位置:程序门 -> vb -> vba



高手帮帮忙吧!!求您了!!!word为什么越来越慢? 


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


高手帮帮忙吧!!求您了!!!word为什么越来越慢?
发表于:2007-12-03 16:52:11 楼主
我在vb开发word中,利用implements     idtextensibility2接口,直接在word中添加工具条,
但时间一长,word运行越来越慢,我查了一下normal.dot模板,已经从68k变成了三百多k   ,太
吓人了,在程序中我一经用setnothing等语句清理了冗余,这究竟是怎么回事啊??
求高手帮帮忙啊!!!!
发表于:2007-12-03 17:11:481楼 得分:0
set   nothing   释放的是内存,normal.dot   的增长与你添加的内容有关,请仔细检查是否重复添加了。
注:normal.dot   在   word   中属于全局唯一的文件,不能每次运行   word   都修改。
发表于:2007-12-03 17:26:592楼 得分:0
有点不懂,重复内容指的是什么啊?   能不能详细说一下,万分感谢!!
发表于:2007-12-04 09:15:143楼 得分:0
你的工具条做什么用?
工具条如何添加到word中?
发表于:2007-12-05 10:35:174楼 得分:0
工具条中的按钮用来自动生成一些文档,这在vb程序里已经写好了
工具条是这样添加的:


有结果了,全部代码如下:
implements   idtextensibility2
public   withevents   apphostapp   as   word.application
private   withevents   cbbbutton   as   office.commandbarbutton


private   sub   apphostapp_documentopen(byval   doc   as   word.document)
set   cbbbutton   =   createbar()
end   sub

private   sub   apphostapp_newdocument(byval   doc   as   word.document)
set   cbbbutton   =   createbar()
end   sub


private   sub   apphostapp_quit()
on   error   resume   next
removetoolbar
end   sub

private   sub   apphostapp_windowactivate(byval   doc   as   word.document,   byval   wn   as   word.window)
set   cbbbutton   =   createbar()
end   sub

private   sub   cbbbutton_click(byval   ctrl   as   office.commandbarbutton,   canceldefault   as   boolean)
msgbox   ("hello   world!")

end   sub

private   sub   idtextensibility2_onaddinsupdate(custom()   as   variant)
'p
end   sub

private   sub   idtextensibility2_onbeginshutdown(custom()   as   variant)
'p
end   sub

private   sub   idtextensibility2_onconnection(byval   application   as   object,   byval   connectmode   as   addindesignerobjects.ext_connectmode,   byval   addininst   as   object,   custom()   as   variant)
      '   存储启动引用
      set   apphostapp   =   application

      '   添加命令条
      set   cbbbutton   =   createbar()


end   sub

private   sub   idtextensibility2_ondisconnection(byval   removemode   as   addindesignerobjects.ext_disconnectmode,   custom()   as   variant)
    removetoolbar
      '   移除要关闭的引用
      set   apphostapp   =   nothing
      set   cbbbutton   =   nothing

end   sub

private   sub   idtextensibility2_onstartupcomplete(custom()   as   variant)
'p
end   sub
public   function   createbar()   as   office.commandbarbutton
      '   指定命令条
      dim   cbcmybar   as   office.commandbar
      dim   btnmybutton   as   office.commandbarbutton

      on   error   goto   createbar_err
      '--------------------
      for   each   br   in   apphostapp.commandbars
      if   br.name   =   "greetingbar"   then
      br.visible   =   true
      set   createbar   =   br.controls(1)
      exit   function
      end   if
      next
      '---------------------

      set   cbcmybar   =   apphostapp.commandbars.add(name:="greetingbar")

      '   指定命令条按钮
      set   btnmybutton   =   cbcmybar.controls.add(type:=msocontrolbutton,   _
            parameter:="greetings")
      with   btnmybutton
            .style   =   msobuttoncaption
            .begingroup   =   true
            .caption   =   "&greetings"
            .tooltiptext   =   "display   hello   world   message"
            .width   =   "24"
end   with

      '   显示并返回命令条
      cbcmybar.visible   =   true
      set   createbar   =   btnmybutton
      exit   function

createbar_err:
      msgbox   err.number   &   vbcrlf   &   err.description
end   function

private   function   removetoolbar()
on   error   resume   next
      apphostapp.commandbars("greetingbar").delete
end   function
发表于:2007-12-05 10:46:215楼 得分:0
看起来代码没问题,而且你也没有对模板进行操作,normal.dot是不应有增长的。
怀疑有宏病毒。
发表于:2007-12-09 15:12:076楼 得分:0
我碰到有一种office   2003不会出现这种情况,其余的normal.dot都会增长
这个office   2003是我在人家那里拷的,也不知道是什么版本,我想这个应该
跟版本没关系吧?


快速检索

最新资讯
热门点击