RE:como cerrar ventanas desde el Visual Basic
Puedes Probar lo siguiente:
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) 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
Const WM_CLOSE = &H10
Const GW_CHILD = 5
Const GW_HWNDFIRST = 0
Const GW_HWNDLAST = 1
Const GW_HWNDNEXT = 2
Const GW_HWNDPREV = 3
Const GW_OWNER = 4
Private Sub CloseAll()
Dim sTitle As String
Dim myHwnd
Dim lReturn As Long
myHwnd = GetWindow(Me.hwnd, GW_OWNER)
Do While myHwnd <> 0
DoEvents
sTitle = GetWinCaption(myHwnd)
If sTitle <> "" Then
lReturn = PostMessage(myhwnd, WM_CLOSE, 0, 0)
If lReturn = 0 Then
msgbox "Error cerrando la Ventana " & sTitle
End If
End If
´get the next window
myHwnd = GetWindow(myHwnd, GW_HWNDNEXT)
Loop
End Sub
Public Function GetWinCaption(hwnd) As String
Dim iTextLength As Integer
Dim sTitle As String
iTextLength = GetWindowTextLength(hwnd)
sTitle = String(iTextLength, 0)
GetWindowText hwnd, sTitle, iTextLength + 1
GetWinCaption = sTitle