与微软视觉基本6.5宏关闭的词

时间:2013-04-05 14:52:48

标签: vba ms-word word-vba

平台:Microsoft Visual Basic 6.5和MS words 2007

我正在尝试做一个宏来对单词启用文件进行一些编辑。完成了关于如何关闭Excel文件而不保存的研究,Santosh已成功帮助我解决问题Solution。尝试应用于单词在编译和保存时没有错误

在TheDocument中放置以下编码,类似于Santosh教我的excel。

Private Sub Workbook_BeforeClose(取消为布尔值)

Me.Close False

End Sub

尝试使用以下编码替换Me.Close False ...

1)Me.close

2)Me.close(false)

3)ActiveDocument.Close

4)ActiveDocument.Close(false)

5)ActiveDocument.Quit

6)Application.Quit(False)

7)Application.Close

但是不起作用。


因为我将使用vba脚本运行脚本来更新我的单词文档并相应地打印到我的值输入。之后,脚本将关闭此文档而不保存(我不提示用户有更改并提示用户保存)。我希望它在没有任何提示的情况下调用“强制关闭”。 对于ms excel 2007 ...我访问开发人员工具转到MS Visual Basic 6.5 在“ThisWorkbook”下......我输入以下命令..

Private Sub Workbook_BeforeClose(取消为布尔值)

Me.Close False

End Sub

此命令成功关闭excel而不保存或任何提示(这是我想要的) 试图将它应用于words2007

Private Sub Document_Close()     'Me.Close'运行时错误'4198'

'Me.Close (SaveChanges:=wdDoNotSaveChanges,OriginalFormat:=wdOriginalDocumentFormat,RouteDocument:=True)

'Me.Quit Savechanges:=wdDoNotSaveChanges

'Me.Close Savechanges:=wdDoNotSaveChanges

'Me.Close False 'run-time error '4198'

'ActiveDocument.Close False 'run-time error '4198'

'Document.Close False 'run time error '424' Object required

'Document.Close Savechanges:=wdDoNotSaveChanges  'run time error '424' Object required


'Document.Close Savechanges 'run time error '424' Object required


'Me.Close Savechanges 'run-time error '4198'  



'Documents.Close SaveChanges:=wdDoNotSaveChanges

End Sub

'Sub CloseAllDocuments() 'Documents.Close SaveChanges:= wdDoNotSaveChanges '结束子

我注释掉的所有这些命令都以错误结束

2 个答案:

答案 0 :(得分:1)

经过多次尝试和研究后,我终于找到了解决方案

这是为任何试图做与我相同的事情的人提供参考。

在“ThisDocument”

中编码

Private Sub Document_Close()

'This is to make the words think that the documents is saved.
'However in actually fact. Any changes would not be save upon closing of document
Me.Saved = True

End Sub

答案 1 :(得分:0)

我不知道该怎么做,但当我遇到同样的问题时,我发现了解决方法。

如果你只打开一个单词进程,只需运行一个脚本就可以关闭它。

TASKKILL /F /IM "WINWORD.EXE"

要从vba运行脚本,请使用

Application.Run "YourPath"

我知道它并不多,但至少它应该照顾你当前的问题。

经过一番询问后,一位朋友告诉我这可能有用

mWord.Quit SaveChanges = wdDoNotSaveChanges

mWord是你的Word.Application