我在vb中调用了word程序,我想在word退出的时候强制保存。请各位大虾指教。谢谢。

解决方案 »

  1.   

    在窗体的申明部分加入如下定义:
    Dim WithEvents wApp As Word.Application  '增加word对象的事件
    Dim WithEvents wDoc As Word.Document    ''增加word文档的事件现在点代码窗靠的左边的下拉框看看,你会发现多了wApp,wDoc两项。你就可以象command一样操作他了。
      

  2.   

    Dim appword As Word.Application
    Dim Document As Word.DocumentDim WithEvents wApp As Word.Application  '增加word对象的事件
    Dim WithEvents wDoc As Word.Document    ''增加word文档的事件Private Sub Form_Load()Set appword = CreateObject("word.Application")
    Set Document = appword.Documents.Add
    appword.Visible = True
    End Sub
    Private Sub wApp_DocumentBeforeClose(ByVal Doc As Word.Document, Cancel As Boolean)
    Label1.Caption = "sdasdf"
    End SubPrivate Sub wApp_Quit()
    Label1.Caption = "sdasdf"
    End SubPrivate Sub wDoc_Close()Label1.Caption = "sdasdf"End Sub
    我将代贴出来,请大虾帮帮忙啊,为什么word的退出事件没有截获到啊?
      

  3.   

    在你的代码里只定义了wApp 的实践,而你用的却是appword.
    这样就好了,我用过的
    Dim WithEvents wApp As Word.Application  '增加word对象的事件
    Dim WithEvents wDoc As Word.Document    ''增加word文档的事件Private Sub Form_Load()
    Set wApp = CreateObject("word.Application")
    Set wDoc = wApp.Documents.Add
    wApp.Visible = True
    End Sub
    Private Sub wApp_DocumentBeforeClose(ByVal Doc As Word.Document, Cancel As Boolean)
    Label1.Caption = "sdasdf"
    End SubPrivate Sub wApp_Quit()
    Label1.Caption = "sdasdf"
    End SubPrivate Sub wDoc_Close()Label1.Caption = "sdasdf"End Sub
      

  4.   

    那請問, 怎樣跳過'是否要保存對話框' 不保存就將word退出?
      

  5.   

    我知道答案了;
    Dim appword As Word.Application
    Dim Document As Word.DocumentDim WithEvents wApp As Word.Application  '增加word對象的事件
    Dim WithEvents wDoc As Word.Document    ''增加word文件的事件Const strDocpath = "\\gcecnsr01\software\public\Customer_Spec\General Spec\S-118.doc"Private Sub Form_Load()Set wApp = CreateObject("word.Application")Set wDoc = wApp.Documents.Open(strDocpath)
    wApp.Visible = True
    End Sub
    Private Sub wApp_DocumentBeforeClose(ByVal Doc As Word.Document, Cancel As Boolean)
    Label1.Caption = "before Close"With wApp
       .Documents.Close SaveChanges:=wdDoNotSaveChanges
       .Quit
    End With
    End SubPrivate Sub wApp_Quit()
    Label1.Caption = "App_quit"
    End SubPrivate Sub wDoc_Close()Label1.Caption = "Doc Close"End Sub
      

  6.   

    用以上的代码,我在试验时就遇到错误。可见还是不到结贴的时候呢。
    Set wApp = CreateObject("word.Application")此处出错了。
    我用的是ms 10.0 word object library.