vba 关闭 word 与 microsoft visual basic 6.5 宏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15837055/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
close word with microsoft visual basic 6.5 macro
提问by Leon
Platform : Microsoft Visual Basic 6.5 and MS words 2007
平台:Microsoft Visual Basic 6.5 和 MS words 2007
I am trying to do a macro to do some editing to an words enable file. Done research on how to close the Excel file without saving, which Santosh had successfully help me solve the problem Solution.Tried applying to words There is no error while compling and saving
我正在尝试做一个宏来对单词启用文件进行一些编辑。研究了如何不保存就关闭Excel文件,Santosh成功帮我解决了问题解决方案。试过应用到words 编译保存没有错误
Placed the following coding in TheDocument similar to where Santosh had teached me for excel.
将以下代码放在 TheDocument 中,类似于 Santosh 教我使用 excel 的地方。
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Me.Close False
End Sub
结束子
tried to replaced Me.Close False with the following coding...
试图用以下编码替换 Me.Close False ......
1) Me.close
1) 我.close
2) Me.close(false)
2) Me.close(false)
3) ActiveDocument.Close
3) ActiveDocument.Close
4) ActiveDocument.Close (false)
4) ActiveDocument.Close (false)
5) ActiveDocument.Quit
5) ActiveDocument.退出
6) Application.Quit (False)
6)Application.Quit(假)
7) Application.Close
7) 申请.关闭
But doesn't work.
但不起作用。
Because I would be using a vba script to run a script to Update my words documents and to print accordingly to my value input. After that the script will close this documents without saving(I don't it to prompt user that there is changes and prompt user to save). I want it to so call "force close" without any prompting. For ms excel 2007... I access the Developer tools to go to MS Visual Basic 6.5 under the "ThisWorkbook"... i enter the following command..
因为我将使用 vba 脚本来运行脚本来更新我的 word 文档并根据我的值输入进行相应的打印。之后脚本将关闭此文档而不保存(我不会提示用户有更改并提示用户保存)。我希望它在没有任何提示的情况下调用“强制关闭”。对于 ms excel 2007...我访问开发人员工具以转到“ThisWorkbook”下的 MS Visual Basic 6.5...我输入以下命令..
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Me.Close False
End Sub
结束子
this command successfully close the excel without saving or any prompt (which is what i want) tried to apply it to words2007
此命令成功关闭excel而不保存或任何提示(这是我想要的)尝试将其应用于words2007
Private Sub Document_Close() 'Me.Close 'run-time error '4198'
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 'End Sub
'Sub CloseAllDocuments() ' Documents.Close SaveChanges:=wdDoNotSaveChanges 'End Sub
all these commands i commented out all ended with errors
我注释掉的所有这些命令都以错误结束
回答by Leon
I finally found a solution after many tries and research
经过多次尝试和研究,我终于找到了解决方案
this is for reference for anyone who is trying to do the same things as mine.
这是任何试图做与我相同的事情的人的参考。
key in this coding in "ThisDocument"
在“ThisDocument”中输入此编码
Private Sub Document_Close()
私有子 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
结束子
回答by FranckMetis
I don't know how to do that but when I had the same problem I found that workaround.
我不知道该怎么做,但是当我遇到同样的问题时,我找到了解决方法。
If you only have 1 word process open just close it by running a script.
如果您只打开 1 个字进程,只需通过运行脚本关闭它。
TASKKILL /F /IM "WINWORD.EXE"
To run a script from vba use
要从 vba 运行脚本,请使用
Application.Run "YourPath"
I know it's not much but at least it should take care of your immediate problem.
我知道这并不多,但至少它应该可以解决您当前的问题。
After some asking around a friend told me this could possibly work
经过一些询问,一位朋友告诉我这可能有效
mWord.Quit SaveChanges = wdDoNotSaveChanges
mWord being your Word.Application
mWord 是您的 Word.Application