Since you only ever need one popup, you could loop over all created instances and remove them:
Module Level
Dim browsers As Object
Dim browserID As Long
WebBrowser
Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
If browsers Is Nothing Then Set browsers = CreateObject("scripting.Dictionary")
Set wbpopup = Me.Controls.Add("Shell.Explorer.2", "Wbbrowser" & browserID, True)
With wbpopup
.Left = Me.WebBrowser1.Width + Me.WebBrowser1.Left + 20
.Top = 10
.RegisterAsBrowser = True
Set ppDisp = .Application
End With
browsers.Add "Wbbrowser" & browserID, wbpopup
browserID = browserID + 1
CommandButton8.Visible = True
With CommandButton8
.ZOrder msoBringToFront
End With
End Sub
Command Button
Private Sub CommandButton8_Click()
Dim x As Long
Dim g
g = browsers.keys
On Error Resume Next
For x = 0 To UBound(g)
Me.Controls.Remove g(x)
Set browsers.Item(g(x)) = Nothing
browsers.Remove g(x)
Next x
On Error GoTo 0
CommandButton8.Visible = False
End Sub
Bookmarks