关闭捕获后的窗口?
我用VB捕获Excel的窗口,使其成为了我的子窗口。现在的问题是:我把Excel窗口关闭了,如何让父窗口;或者是如何在父窗口上关闭Excel窗口?或者说如何在父窗口上操控Excel窗口?
哪位高手帮帮忙,谢谢了!!! --------------------编程问答-------------------- 啊,没人回复,谁帮帮忙,急急!!!!!!
自已先顶一个! --------------------编程问答-------------------- 非常简单:
取得EXCEL的实例,退出即可.
Private Sub Command1_Click()--------------------编程问答--------------------
Dim xlApp As Object
Set xlApp = GetObject(, "Excel.Application") '取得当前EXCEL实例
xlApp.Quit '退出
Set xlApp = Nothing '释放xlApp对象
End Sub
--------------------编程问答-------------------- 2楼myjian 你好:
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 "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_CLOSE = &H10
Public Function ExitProgram(ByVal strCaption As String) As Boolean '根据窗体的标题关闭窗口
Dim winHwnd As Long
Dim RetVal As Long
ExitProgram = True
winHwnd = FindWindow(vbNullString, strCaption)
Debug.Print winHwnd
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
If RetVal = 0 Then
ExitProgram = False
End If
Else
ExitProgram = False
End If
End Function
EXCEL已被我捕获到父窗口里,这时还能取得他的实例吗? --------------------编程问答-------------------- 3楼的方法我用过了,可是关不了EXCEL窗口,EXCEL进程也在 --------------------编程问答--------------------
这与窗口无关
EXCEL与WORD这些OFFICE软件都会建立一个ActiveX服务器,直接使用其对象即可.
你试一下不就行了,反正就几行代码. --------------------编程问答-------------------- 谢谢myjian !
那现在又出现一个问题,那就是如何使Excel窗口的关闭按钮失效?这样才能通过主窗口来关闭,才不会引起后续程序的错误!谢谢再帮帮忙!
补充:VB , API