我打开了两个excel文件实例。我想关闭其中一个实例,这样当我转到任务管理器时,将不会有EXCEL.exe在此过程中运行的痕迹。我从用户表单中打开了两个excel。我在excel文件中有一个按钮来关闭excel工作簿,
=== this is vb.net
public sub openExcel()
my code.... blah blah blah....
'open excel
Dim xlsApp As Excel.Application
Dim xlsWB As Excel.Workbook
xlsApp = New Excel.Application
xlsApp.Visible = True
xlsWB = xlsApp.Workbooks.Open(c:\myExcelFile.xlsm")
end sub
======= this is vba
ThisWorkbook.Save
Application.DisplayAlerts = True
Application.Quit
关闭其中一个文件后,我仍然收到EXCEL.exe。
答案 0 :(得分:0)
希望这会有所帮助:
' ------如果您要关闭原始的opend工作簿。
===这是vb.net
public sub openExcel()
Dim NameW As String
NameW = ThisWorkbook.name ' get the name of the opened workbook
my code.... blah blah blah....
'open excel
Dim xlsApp As Excel.Application
Dim xlsWB As Excel.Workbook
xlsApp = New Excel.Application
xlsApp.Visible = True
xlsWB = xlsApp.Workbooks.Open(c:\myExcelFile.xlsm")
Workbooks(NameW).Close ' close the workbook
end sub
======= this is vba
ThisWorkbook.Save
Application.DisplayAlerts = True
Application.Quit
否则,如果您要关闭的活动工作簿可以使用:
ActiveWorkbook.Close
答案 1 :(得分:0)
如果你这样做:
xlsWB = xlsApp.Workbooks.Open(c:\myExcelFile1.xlsm")
xlsWB = xlsApp.Workbooks.Open(c:\myExcelFile2.xlsm")
它应该只打开1个Excel实例(如任务管理器中所示)。
如果你这样做 - 它会打开2个实例。所以基本上只是跟踪第一个实例并重复使用它。
xlsApp1 = New Excel.Application
xlsApp2 = New Excel.Application