第1个回答 推荐于2016-02-25
sub aa()
workdir = ActiveWorkbook.Path '获取当前路劲(C:\dcam\pmill2\程序单)
Workbooks.Open Filename:=workdir + "\Temp1.xls" '打开Temp1.xls
Windows("Temp1.xls").Activate
Application.DisplayAlerts = False ‘避免弹出对话框
'ActiveWorkbook.Save '保存表格,此处不保存
ActiveWorkbook.Close '关闭Temp1.xls
Application.DisplayAlerts = True
end sub本回答被提问者采纳
第3个回答 2012-04-18
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Sub Command1_Click()
Dim hWnd As Long
hWnd = FindWindow("XLMAIN", "Microsoft Excel - Temp1.xls")
KillProcess hWnd
End Sub
Private Sub KillProcess(ByVal whWnd As Long)
Dim lpdwProcessId As Long
Dim hProcessHandle As Long
GetWindowThreadProcessId whWnd, lpdwProcessId
hProcessHandle = OpenProcess(&H1F0FFF, True, lpdwProcessId)
Dim success As Long
If hProcessHandle <> 0 Then
success = TerminateProcess(hProcessHandle, ByVal 0&)
End If
If success = 1 Then CloseHandle (hProcessHandle)
End Sub