问题
Has anyone tried using a webbrowser control on a multipage control, when you switch between the pages and then switch back again the webbrowser control diss-appears?
回答1:
web browser control not working on the multipage control seems a common problem, and so far I did not see a solution.
Here is the solution I devised. It merely re-creates the web browser control each time the page is selected.
Dim wbr As SHDocVw.WebBrowser
Private Sub MultiPage1_Change()
If MultiPage1.SelectedItem.Name = "Page 1" Then
Set wbr = Nothing
Set wbr = Me.MultiPage1.SelectedItem.Controls.Add("Shell.Explorer.2")
wbr.Height = 700
wbr.Left = 96
wbr.Top = 24
wbr.Width = 570
wbr.Navigate "About:Blank"
wbr.Document.write "<HTML><Body><embed src=""file:///C:\Users\User\File.pdf"" width=100% height=100%/></Body></HTML>"
wbr.Document.body.scroll = "no"
End If
End Sub
Private Sub UserForm_Initialize()
Set wbr = Me.MultiPage1.SelectedItem.Controls.Add("Shell.Explorer.2")
wbr.Height = 700
wbr.Left = 96
wbr.Top = 24
wbr.Width = 570
wbr.Navigate "About:Blank"
wbr.Document.write "<HTML><Body><embed src=""file:///C:\Users\User\File.pdf"" width=100% height=100%/></Body></HTML>"
wbr.Document.body.scroll = "no"
End Sub
回答2:
You can also use the tab control with several webbrowser. This option has the advantage of keeping the last loaded web page of the gadget.Just create a tab control with the desired web page number. For the dimensions of webbrowser, I suggest you visually create one and take its coordinates before destroying it. Here is the code to use.
enter code here
Dim webbrowser(3)
Dim actuelpage
Private Sub TabStrip1_Change()
webbrowser(actuelpage).Visible = False
actuelpage = Me.TabStrip1.SelectedItem.Index
webbrowser(actuelpage).Visible = True
End Sub
Private Sub UserForm_Activate()
Dim pages As Variant
pages = Array("www.google.com", "www.allo.com", "www.microsoft.com")
For a = 0 To UBound(webbrowser) - 1
Set webbrowser(a) = Me.Controls.Add("Shell.Explorer.2")
webbrowser(a).Height = 306
webbrowser(a).Left = 30
webbrowser(a).Top = 42
webbrowser(a).Width = 684
webbrowser(a).Silent = True
webbrowser(a).navigate pages(a)
webbrowser(a).Visible = False
Next a
actuelpage = 0
webbrowser(actuelpage).Visible = True
End Sub
enter code here
来源:https://stackoverflow.com/questions/52178224/excel-userform-webbrowser-control-on-multipage-control