Having made an instance of IE as a child of ThisWorkbook via API SetParent oIE.hwnd, Application.hwnd, I CANNOT now release the child from its parent.

Using Excel 2016: In the following code:  Sub getIE_makeChild_ofXl() opens internet explorer as a child of ThisWorkbook.
As expected, when the workbook is dragged, the IE wondow moves. When the excel.App.window is clicked, the IE window remains on top of thisWorkbook

However, I could not release IE from its parent either via Sub releaseParent1() nor via Sub releaseParent2().

Can you help me to release the child window?
Thanks, Kelvin

Option Explicit

#If Win64 Then
    'source (Chip Pearson) https://www.pcreview.co.uk/threads/in-vba-make-ie-browser-object-always-in-foreground.2503326/
    Declare Function SetParent Lib "user32" (ByVal hWndChild As LongLong, ByVal hWndNewParent As Long) As LongLong

    'source: http://www.vbforums.com/showthread.php?526112-RESOLVED-Undo-SetParent
    Declare Function GetDesktopWindow Lib "user32.dll" () As LongLong
#Else
    Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    Declare Function GetDesktopWindow Lib "user32.dll" () As Long
#End If

Private oIE As Object

'this places the IE window ontop of the Excel sheet window, U can drag it about to see the xl window,
'' but the VISIBLE part of the IE window is that WITHIN the margins of the xl window.
   
Sub getIE_makeChild_ofXl()
   
    Set oIE = CreateObject("InternetExplorer.application")
    oIE.Visible = True
    oIE.navigate ("http://bbc.co.uk")
    oIE.Visible = True
   
    'make child
    SetParent oIE.hwnd, Application.hwnd

End Sub

Sub releaseParent1()

'source: http://www.vbforums.com/showthread.php?526112-RESOLVED-Undo-SetParent
    SetParent oIE.hwnd, GetDesktopWindow()
End Sub

Sub releaseParent2()
    'source: http://www.xtremevbtalk.com/general/262412-desktop-hwnd.html
Dim hWndDesktop As Long
   
    hWndDesktop = GetDesktopWindow
    SetParent oIE.hwnd, hWndDesktop
End Sub
Kelvin4Asked:
Who is Participating?
 
pcelbaCommented:
You can also issue
oIE.Quit
Set oIE = Null
which is better way of the cleanup.

Set oIE = Nothing
could also work
0
 
NorieVBA ExpertCommented:
Kelvin

What happens when you run releaseParent1 or releaseParent2?
0
 
Kelvin4Author Commented:
Hi Norie,
No sign of a bug with either releaseParent1 or releaseParent2.
However, before attempting release, IE is on top of the Green header band behind the Xl fluent ribbonTop panel shows IE as child of xl parent, next panel: after releaseParent1(), bottom panel: after releaseParent2()
After :  releaseParent1() or releaseParent2() the full header region of xl is ON TOP of IE; but IE is on top of the worksheet, and still moves with xl when xl is dragged.

I dont have the knowledge to try to put in reporters for API processes, but I can try under instruction.
Would you like to have the xl file?

Many thanks
Kelvin
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
NorieVBA ExpertCommented:
Kelvin

It probably would help to see the file.
0
 
Kelvin4Author Commented:
Attached is the file, thanks.
Kelvin
1.-setParent-of-excel.xlsm
0
 
Kelvin4Author Commented:
Sub releaseParent3()
         'also failed to release
         'source: http://www.jasinskionline.com/windowsapi/ref/s/setparent.html
    SetParent oIE.hWnd, 0
End Sub

At present, my best work around is to set the child IE .visible = false, and recall it to view with .visible = true.
To unload the child IE, I need to close xl and re-open.
0
 
Kelvin4Author Commented:
Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.