Dim cx As Word.ApplicationPrivate Sub Command1_Click()
Set cx = New Word.Application
cx.Visible = True
cx.Documents.Add
cx.WindowState = wdWindowStateMaximize
'使Word它的关闭按钮无效的代码
End Sub在Command1单击事件中打开WORD文档后我想将WORD的关闭按钮无效不起作用
请大家指教

解决方案 »

  1.   

    Private WithEvents cx As Word.ApplicationPrivate Sub Command1_Click()
    Set cx = New Word.Application
    cx.Visible = True
    cx.Documents.Add
    cx.WindowState = wdWindowStateMaximize
    '使Word它的关闭按钮无效的代码
    End SubPrivate Sub cx_DocumentBeforeClose(ByVal Doc As Word.Document, Cancel As Boolean)
     MsgBox "不能关闭"
     Cancel = True
    End Sub
      

  2.   

    你这样看看有没有反应
    Private WithEvents cx As Word.ApplicationPrivate Sub Command1_Click()
    Set cx = New Word.Application
    cx.Visible = True
    cx.Documents.Add
    cx.WindowState = wdWindowStateMaximize
    cx.visible=true '使Word 可见
    End SubPrivate Sub cx_DocumentBeforeClose(ByVal Doc As Word.Document, Cancel As Boolean)
     MsgBox "不能关闭"
     Cancel = True
    End Sub然后在程序外,手工X掉你程序打开的文档,则VB程序会弹出信息框
    我的可以正确弹出对话框
      

  3.   

    可以了,原来是我机台子的问题,谢谢大家的帮忙!
    现在想让Word新建文档(即按新建文档按钮、菜单无效)
    请大家再帮帮忙
      

  4.   

    上一条打漏字。意思是说:
    现在不想让Word新建文档(即按新建文档按钮、菜单无效)
    请大家再帮帮忙
      

  5.   

    cx.CommandBars.FindControl(ID:=18).Enabled = False
    cx.CommandBars.FindControl(ID:=2520).Enabled = False
    cx.CommandBars.FindControl(ID:=3813).Enabled = False
      

  6.   

    cx.CommandBars.FindControl(ID:=18).Enabled = False
    cx.CommandBars.FindControl(ID:=2520).Enabled = False
    cx.CommandBars.FindControl(ID:=3813).Enabled = False上面的代码只能将新建文档按钮、菜单无效,但是按Ctrl+n还可以新建一个文档能不能控制它不能新建文档呢?还望你帮帮忙
    谢谢
      

  7.   

    cx.CustomizationContext =cx.NormalTemplate
    cx.FindKey(BuildKeyCode(Arg1:=wdKeyControl, Arg2:=wdKeyN)).Disable
      

  8.   

    改一点
    cx.CustomizationContext =cx.NormalTemplate
    cx.FindKey(cx.BuildKeyCode(Arg1:=wdKeyControl, Arg2:=wdKeyN)).Disable