1

以前我用过这个:

Private Sub Document_Close()
    Me.Saved = True
End Sub

在退出 Word 文档并进行更改时禁用保存提示,但是我添加了一个“组合框(ActiveX 控件)”,现在 Word 再次提示保存。有没有解决的办法?

我尝试编写代码以在文档关闭时删除组合框,但该框在使用后会自行删除(不是我的代码,它只是这样做),然后当文档关闭时该框不存在并导致错误那里。我可以做一个如果存在/错误控制,但我觉得这只是变得草率而不是找到根本问题......有人可以帮忙吗?

4

1 回答 1

1

如果遇到同样的问题,并通过 Bing 找到解决方案:http: //answers.microsoft.com/en-us/office/forum/office_2007-customize/activex-control-blocks-ms-word-vba/71eca664-8e43 -4e4f-84c5-59154661ee5a

以下代码帮助我解决了这个问题:

Dim WithEvents App As Application

Private Sub App_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)
  'Did the user saved our file?
  If Not ThisDocument.Saved Then
    'Close our file?
    If Doc.Name = ThisDocument.Name Then
      'Cancel the dialog always!
      Cancel = True
      'Set the save state
      ThisDocument.Saved = True
      'Close the document after this event
      Application.OnTime Now + TimeSerial(0, 0, 1), Me.CodeName & ".Document_AfterClose"
    End If
  End If
End Sub

Sub Document_AfterClose()
  'Close the document without saving
  ThisDocument.Close False
End Sub

Private Sub cboEquip_Change()
  'Let the document know that a change is made
  ThisDocument.Saved = False
End Sub

Private Sub Document_Open()
  Set App = Application
End Sub
于 2013-02-25T15:47:51.123 回答