2013-02-12 97 views
1

以前我已经使用这个:ActiveX控件块Me.Saved =真

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

禁用离开Word文档和变化当已经进行了保存提示,但是我添加了一个“组合框(的ActiveX控制)“,现在Word正在提示再次保存。有没有解决的办法?

我试过编写代码来在文档关闭时删除组合框,但是在使用后删除自己(不是我的代码,它只是),然后当文档关闭框不存在时并在那里导致错误。我可以做一个if exists/error控件,但我觉得这只是变得sl instead而不是找到根本问题......有人可以帮忙吗?

+0

又是怎么回事Application.DisplayAlerts = wdAlertsNone 的ActiveDocument 。关闭SaveChanges:= False? – dee 2013-02-12 21:21:43

+0

@DanielDusek我只是在'Private Sub Document_Open()'中尝试了'Application.DisplayAlerts = wdAlertsNone',并且在'Private Sub Document_Close()'中单独调用了'ActiveDocument.Close SaveChanges:= False',并且都没有工作。我把他们放在错误的地方? 我有'ActiveDocument.Close SaveChanges:= False'正在使用当用户点击一个按钮(执行其他程序后),但如果某人偶然打开文档或不想使用它,关闭它与顶部右键[X]按钮仍然显示提示。 – Daevin 2013-02-14 19:31:15

回答

1

如果有同样的问题,并发现了冰的解决方案: 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 
+0

感谢您的回应!然而,如果你看看发布该问题的用户......:P在这里有一些看法,但没有答案,所以我去了MS论坛。谢谢你的回应,非常感谢你的帮助! – Daevin 2013-03-05 15:24:53

+0

大声笑,没有注意到这是你在MS论坛上的问题。 – Arnoldiusss 2013-03-05 22:27:04