Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA button to close browser child and focus on parent window

Status
Not open for further replies.

Kruzer

Programmer
Jun 16, 2000
117
US
Hello All,

Never written any code for VBA that sends a response from Excel to a Internet browser window.

Here's my dilema, I have a internet browser window with a submit button that opens up a vba app. With in the vba app I have a button. How do I use the button in the vba app to close the vba app and gain focus back on the internet browser window?

Private Sub CommandButton1_Click()
???
End Sub
Dano
dskryzer@hotmail.com
What's your major malfunction
 
'*****insert this code into a MODULE
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd 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 GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Type WindR 'Store running proc in structure
Name As String
hwnd As Long
cLaSS As String
End Type
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2


Public Sub LoadTaskList()
Dim CurrWnd As Long
Dim Length As Long
Dim TaskName As String
Dim Parent As Long
Dim dk() As WindR
Dim lpClassName As String
Dim i, k As Integer
Dim lNull As String
s = FindWindow("XLMAIN", Application.Caption)
CurrWnd = GetWindow(s, GW_HWNDFIRST)
i = 1
While CurrWnd <> 0
Parent = GetParent(CurrWnd)
Length = GetWindowTextLength(CurrWnd)
TaskName = Space$(Length + 1)
Length = GetWindowText(CurrWnd, TaskName, Length + 1)
TaskName = Left$(TaskName, Len(TaskName) - 1)

If Length > 0 Then
If TaskName <> Application.Caption Then
lpClassName = Space(256)
ReDim Preserve dk(i)
dk(i).Name = TaskName
k = GetClassName(CurrWnd, lpClassName, 256)
dk(i).cLaSS = Left(lpClassName, InStr(lpClassName, vbNullChar) - 1)
dk(i).hwnd = CurrWnd
If dk(i).cLaSS = &quot;IEFrame&quot; Then _
AppActivate dk(i).Name 'if the current class=&quot;IEFRAME&quot; (internet explorer) then activate it
i = i + 1
End If
End If
CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
DoEvents
Wend
Application.Quit 'quit the application of this project
End Sub


'*******YOUR CODE
Private Sub CommandButton1_Click()
LoadTaskList
End Sub

ide
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top