PDA

View Full Version : [SOLVED:] How to suppress JavaScript errors when loading a webpage into a WebBroswer control



Poundland
08-16-2016, 03:27 AM
Hi Guys,

I am full into a project for my company, building a Dashboard using Excel Userform to display company information immediately.

I have added a WebBrowser control and have adding code to load up a webpage into the Browser, the issue I am having is that I keep getting JavaScripting errors as the page is loading or any interaction with the page is made.

I have scoured other forums, and this one, and have found some code to use, but either I am using it incorrectly, or I am placing it in the incorrect Procedures I do not know...

My code for loading the WebBrowser control is below and is part of larger code to initialize the User form.

Also below is code to Load the Userform, using various methods.

And finally some of the Code Lines I have scoured from the Internet.

Please can you guys let me know how I can suppress the scripting errors.

Part of my Initialization code


[Private Sub UserForm_Initialize()
Dim Factor As Single
Dim Verify As Range, Chk As Range, strBU As String
Dim pdat As Date
' Factor = 0.73 'adjust to suit
' Me.Width = GetSystemMetrics32(0) * Factor '< in pixels
' Me.Height = GetSystemMetrics32(1) * Factor

Application.DisplayAlerts = False
Me.WebBrowser1.Navigate "http://www.bbc.co.uk/weather/2635167#outlook"
Application.DisplayAlerts = True

Various routines to Load the Userform


Private Sub Workbook_Open()
On Error Resume Next
Application.DisplayAlerts = False
ThisWorkbook.ChangeFileAccess Mode:=xlReadOnly
'ThisWorkbook.ChangeFileAccess Mode:=xlReadWrite
On Error GoTo 0
Application.WindowState = xlMaximized
Application.DisplayAlerts = True
Call Main
UserForm1.Show
End Sub


and


Private Sub CommandButton1_Click()
UserForm1.Show
End Sub

And finally the various Code Lines I have found on the Internet but do not know how to use them and where to place them in my procedures.


webBrowser1.ScriptErrorsSuppressed = true;

and


[WebBrowser1.Silent = True

Thanking you guys in advance for your assistance.

Poundland
08-16-2016, 06:30 AM
OK,I have solved this issue now but have discovered another one.

The solution for this issue on this Thread was to put the Silent code line before the navigation on the WebBrowser, see code line below. This now suppresses the JavaScripting error messages.

The new issue I have I will create a new thread for.


WebBrowser1.Silent = True
WebBrowser2.Silent = True
Me.WebBrowser1.Navigate "http://www.supermarket.co.uk/food-prices.aspx"
Me.WebBrowser2.Navigate "http://www.bbc.co.uk/weather/2633912"