MailMerge 似乎打开 Excel 文件两次?

发布于 2024-08-05 11:05:41 字数 367 浏览 6 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冬天的雪花 2024-08-12 11:05:41

可以使用此 VBA 代码关闭工作簿

Workbooks("BOOK1.XLS").Close

您可以将其添加到末尾,这样如果文件已更新但未保存,则不会显示保存提示。

 SaveChanges:=False

如果从 Excel 内部调用,则可以通过 VBA 关闭 Excel。

Application.Quit

如果从 Excel 外部调用,您将需要设置对 Excel 的引用,然后将其关闭。

Set appExcel = GetObject(, "Excel.Application")
appExcel.Quit 

需要确保所有工作簿都关闭或保存,否则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.

 SaveChanges:=False

Excel can be closed via VBA with if called from within Excel.

Application.Quit

If called from outside Excel, you will need to set a reference to Excel and then close it.

Set appExcel = GetObject(, "Excel.Application")
appExcel.Quit 

You need to ensure that all Workbooks are closed or saved, otherwise Excel will prompt the user to save

物价感观 2024-08-12 11:05:41

来自 VBA:

Dim objWMIcimv2 As Object
Dim objProcess As Object
Dim objList As Object
Dim errCode As Integer

Set objWMIcimv2 = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2") 'Connect to CIMV2 Namespace

Set objList = objWMIcimv2.ExecQuery _
("select * from win32_process where name='EXCEL.EXE'") 'Find the process to terminate

For Each objProcess In objList

    errCode = objProcess.Terminate 'Terminates a process and all of its threads.

Next

将杀死 Excel 的所有实例。

From VBA:

Dim objWMIcimv2 As Object
Dim objProcess As Object
Dim objList As Object
Dim errCode As Integer

Set objWMIcimv2 = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2") 'Connect to CIMV2 Namespace

Set objList = objWMIcimv2.ExecQuery _
("select * from win32_process where name='EXCEL.EXE'") 'Find the process to terminate

For Each objProcess In objList

    errCode = objProcess.Terminate 'Terminates a process and all of its threads.

Next

Would kill all instances of Excel.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文