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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
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
NorieAnalyst Assistant Commented:
Kelvin

It probably would help to see the file.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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
pcelbaCommented:
You can also issue
oIE.Quit
Set oIE = Null
which is better way of the cleanup.

Set oIE = Nothing
could also work
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kelvin4Author Commented:
Thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.