MailMerge 似乎打开 Excel 文件两次?
With ActiveDocument.MailMerge
.MainDocumentType = wdCatalog
.OpenDataSource Name:=excelfile, _
Connection:="Entire spreadsheet", SubType:=8, ReadOnly:=True
''# Range = Selection.Range
.Destination = wdSendToNewDocument
.Execute
End With ''# Activedocument
DDETerminateAll
为什么这段代码打开“excelfile”两次到excel,其中之一是只读的。如何从 Word 中关闭这些 Excel 文件?
With ActiveDocument.MailMerge
.MainDocumentType = wdCatalog
.OpenDataSource Name:=excelfile, _
Connection:="Entire spreadsheet", SubType:=8, ReadOnly:=True
''# Range = Selection.Range
.Destination = wdSendToNewDocument
.Execute
End With ''# Activedocument
DDETerminateAll
Why does this code open "excelfile" twice to excel, one of these is readonly. How can I close these Excel files from Word?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以使用此 VBA 代码关闭工作簿
Workbooks("BOOK1.XLS").Close
您可以将其添加到末尾,这样如果文件已更新但未保存,则不会显示保存提示。
如果从 Excel 内部调用,则可以通过 VBA 关闭 Excel。
如果从 Excel 外部调用,您将需要设置对 Excel 的引用,然后将其关闭。
需要确保所有工作簿都关闭或保存,否则Excel会提示用户保存
Workbooks can be closed with this VBA code
Workbooks("BOOK1.XLS").Close
You can add this to the end, so that no prompts to save are displayed if the file has been updated and not saved.
Excel can be closed via VBA with if called from within Excel.
If called from outside Excel, you will need to set a reference to Excel and then close it.
You need to ensure that all Workbooks are closed or saved, otherwise Excel will prompt the user to save
来自 VBA:
将杀死 Excel 的所有实例。
From VBA:
Would kill all instances of Excel.