0

I access a website through VBA. This website has a security certificate.

Is there a way to get through this warning and go straight to the webpage.

Sub Certificate() Dim IE As Object Set IE = CreateObject("InternetExplorer.Application") With IE .Visible = True .navigate ("Website URL") While IE.ReadyState <> 4 DoEvents Wend {Application.Wait (Now + TimeValue("0:00:05"))}--Optional 'This is the security certificates webpage HTML 'This clicks the not recommended but continue to website button IE.document.getElementsByName("overridelink").Item.Click End With End Sub 

When I execute this code this line:

IE.document.getElementsByName("overridelink").Item.Click 

gives me a

Runtime error '91'

This code works when the security certificate warning pops up however it doesn't always pop up and goes straight to the website, giving me that error.

I've gone into internet options and unchecked everything that would cause that warning as well as adding it to trusted site.

1 Answer 1

1

CAUTION! Use sparingly!

If the only time you get an error with the line IE.document.getElementsByName("overridelink").Item.Click is because you don't need it, you can use this:

On Error Resume Next IE.document.getElementsByName("overridelink").Item.Click On Error Goto 0 

instead of:

IE.document.getElementsByName("overridelink").Item.Click 

CAUTION! Read this:

Make sure to include the On Error Goto 0 line directly after the section you want the error ignored on, as that line resets the error-behavior to default. Otherwise, the On Error Resume Next will mask any and all other errors in the code following it. This can cause HUGE issues with code giving unexpected results for no apparent reason and/or attempts to troubleshoot problematic code.

Another issue: if the error-skipping enclosed code goes wrong for an unexpected reason, you won't have any way of catching this unless you set-up a more elaborate error catching section in your code.

Sign up to request clarification or add additional context in comments.

Comments