|
关闭正打开的文件:
========================
Attribute VB_Name = "关闭正打开的文件"
Option Compare Database
'原理:先用FindWindow找到程序窗体,然后用SendMessage向这个窗口应答。
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "ostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
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
Private Const WM_SYSCOMMAND = &H112
Private Const SC_MINIMIZE = &HF020&
Private Const WM_CLOSE = &H10
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Dim windowsH As Long
Public Sub close_excelfile()
'If IsOpen(CurrentProject.Path & "\123.xls") = True Then
a = FindWindow(vbNullString, "microsoft excel - 123")
Debug.Print a
b = PostMessage(a, WM_CLOSE, 0, 0)
Debug.Print b
'End If
End Sub
|
|