vb 如何关闭所有打开的EXCEL文件

2024-11-07 13:46:07
有3个网友回答
网友(1):

alt+ctrl+delete→单击“进程”选项卡→点击“excel.exe”→结束进程,全部关闭!但好像不能提示你是不是要保存,要注意了

网友(2):

'把这个写在模块里,要关闭什么就调用propath("程序名.exe"),
'如关闭excel就propath("EXCEL.EXE")
Public Function propath(proname As String) As String
Dim objWMIService As Object
Dim colProcesslist As Object
Dim objProcess As Object
Set objWMIService = CreateObject("winmgmts:{impersonationLevel=Impersonate}!root\cimv2")
Set colProcesslist = objWMIService.ExecQuery("select * from win32_process where name=" & Chr(39) & proname & Chr(39))
For Each objProcess In colProcesslist
propath = objProcess.ExecutablePath
objProcess.Terminate '关闭程序
Next
End Function

网友(3):

窗体上放一TIMER,它的INTERVAL属性设置为10
Private Declare Function FindWindow% Lib "user32" Alias "FindWindowA" (ByVal lpclassname As Any, ByVal lpCaption As Any)
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const NILL = 0&
Const WM_SYSCOMMAND = &H112
Const SC_CLOSE = &HF060

Private Sub Timer1_Timer()
Dim hwnd%
hwnd% = FindWindow%("XLMAIN", 0&)
X& = SendMessage(hwnd%, WM_SYSCOMMAND, SC_CLOSE, NILL)
End Sub