vba error message 13 IE.document - vba

I see that someone else has asked the same question but the answer didn`t help so I am having to raise it once more,
I am running Windows 10 internet explorer 11, 64 bit
I get error mismatch error 13 at last line
I have tried Dim IE As New InternetExplorer and Dim IE As New InternetExplorerMedium but still same error ..
any idea who I can get rid of the error please ?
Thanks
Sub test()
Dim IE As Object ' InternetExplorer
Set IE = CreateObject("internetexplorer.application")
Dim html As HTMLDocument
Set IE = New InternetExplorer
IE.Visible = True
IE.navigate "http://stackoverflow.com/"
'wait while web page load
Set html = IE.document
end sub

Try using late binding instead for the HTMLDocument. Typically you don't need to assign the document to an object, you can just interact with it without assigning it to something else.
Sub test()
Dim IE As New InternetExplorer ' Make sure you have Microsoft Internet Controls Reference added
Dim html As Object ' Or you can use HtmlDocument as the type if Microsoft HTML Object Reference is added
With IE
.Visible = True
.navigate "http://stackoverflow.com/"
While .busy Or .readystate <> 4
Application.Wait (Now() + TimeValue("00:00:01"))
DoEvents
Wend
Set html = .document
End With
End Sub

Related

The remote server machine does not exist or is unavailable for specific website

I tried to open website using below VBA code:
Dim IE As Object
Dim doc As Object
Dim strURL As String
Set IE = CreateObject("InternetExplorer.Application")
With IE '
.Visible = True
.navigate "https://Google.com"
Do Until .readyState = 4
DoEvents
Loop
It's working for website like "google" etc.
But when I tried to open specific site like my company PLM " Agile (https://agileplm.XXXX.com/Agile/default/login-cms.jsp)" throwing error
"The remote server machine does not exist or is unavailable"
I could open the web page on explorer but throwing error while executing from below line
Do Until .readyState = 4
DoEvents
Loop
Is this due to any protection over site or not?
I used early binding on this and created the object InternetExplorerMedium rather than InternetExplorer and it seemed to work.
The issue is that Internet Explorer disconnects from VBA (In my case some internal security settings). The solution is to reconnect Internet Explorer to VBA:
Include this code after the line IE is not responsive anymore and the existing Internet Explorer window will be assigned to = IEObject1
Dim shellWins As SHDocVw.ShellWindows
Dim explorer As SHDocVw.InternetExplorer
Set shellWins = New SHDocVw.ShellWindows
For Each explorer In shellWins
If explorer.Name = "Internet Explorer" Then
Set IEObject1 = explorer
Debug.Print explorer.LocationURL
Debug.Print explorer.LocationName
End If
Next
Set shellWins = Nothing
Set explorer = Nothing
If you have several IE windows open then this code picks the last one. You can choose between the windows by using the URL or LocationName if you need several open windows.
Try to make a test with example code below may help you to solve your issue.
Sub Automate_IE_Load_Page()
'This will load a webpage in IE
Dim i As Long
Dim URL As String
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
'Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
'Set IE.Visible = True to make IE visible, or False for IE to run in the background
IE.Visible = True
'Define URL
URL = "https://agileplm.xxxx.com/Agile/default/login-cms.jsp"
'Navigate to URL
IE.Navigate URL
' Statusbar let's user know website is loading
Application.StatusBar = URL & " is loading. Please wait..."
' Wait while IE loading...
'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertently skipping over the second loop)
Do While IE.ReadyState = 4: DoEvents: Loop 'Do While
Do Until IE.ReadyState = 4: DoEvents: Loop 'Do Until
'Webpage Loaded
Application.StatusBar = URL & " Loaded"
'Unload IE
Set IE = Nothing
Set objElement = Nothing
Set objCollection = Nothing
End Sub
Reference:
Automate Internet Explorer (IE) Using VBA
If your issue persist than try to provide a detailed information, Whether you are having issue with opening the page or you got an error while checking the ready state of IE. We will try to provide further suggestions.
Dim IE As Object
Dim doc As Object
Dim strURL As String
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.navigate "https://Google.com"
End With
For Each win In CreateObject("Shell.Application").Windows
If win.Name Like "*Internet Explorer" Then
Set IE = win: Exit For
End If
Next
With IE
Do Until .readyState = 4
DoEvents
Loop

vba internet explorer delete object

I'm making simple vba script witch is gonna open IE, get some informations and exit. Script open IE 35 times without problem, but after that it, works, but doesn't open IE anymore.
Sub Test()
for x=1 to 50
Dim objIE As Object
Set objIE = New InternetExplorer
Set objIE = New InternetExplorerMedium
objIE.Visible = True
objIE.Navigate2 "http://www.google.com"
objIE.Visible = False
Set objIE = Nothing
next x
End Sub
I don't really get what you want do with your code, but here some tips that might help to fix the issue:
You can take both the declaration and the set of your browser out of the loop, you don't need to declare it and set it each time:
Dim objIE As Object
Set objIE = New InternetExplorerMedium
Why are you setting objIE as New InternetExplorer, if you're right after setting it again as New InternetExplorerMedium? That action is useless.
Between the objIE.Navigate2 "http://www.google.com" and the Set objIE = Nothing you should probably wait some time, at least with a Do While objIE.busy Loop, because you don't even give the browser the time to load the document and you already destroy it.
The Set objIE = Nothing can also be put out of the loop, you can re-use the same browser to navigate as many links as you want. Also, don't forget to quit it first before destroying it from memory with objIE.quit
If it works 35 times and keep on "working but doing nothing" starting from the 36th, wonder about the links are corrupted when you get there.
You can check that with a Debug.Print on the link you're going to navigate each time.
This is the basic structure to automate IE with VBA.
Option Explicit
Sub PAO()
Dim IE As InternetExplorer
Dim url As String
Const url$ = "http://www.google.com"
Set IE = CreateObject("internetexplorer.application")
IE.Visible = True
IE.navigate url
Set IE = Nothing
End Sub
Also, here is a Wait function that can help you to wait for the webpage to load.
Function IEWait(t As Long)
Do While IE.Busy
Application.Wait DateAdd("s", t, Now)
Loop
End Function
This is how you use the function:
IEWait (1)
Do Until IE.readyState = READYSTATE_COMPLETE: DoEvents: Loop
Hope this will help you but let me know if you have any question.

Clicking link within a HTML List

I'm trying use Excel's IE automation tools to click a website link within a users profile of this site. Using the following in VBA:
ie.Document.getElementsByClassName("website")(0).getElementsByTagName("a")(0).Click
But keep getting the Runtime error '438' when ran. Any advice on how to fix this or if clicking this link is even possible please? Thanks.
EDIT (Full Code):
Dim ie As InternetExplorer
Dim html As HTMLDocument
Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "site"
Do While ie.READYSTATE <> READYSTATE_COMPLETE
DoEvents
Loop
Set objA = ie.Document.getElementsByClassName("website")(0) 'GETTIN ERROR HERE
objA.getElementsByTagName("a")(0).Click
End Sub
It would appear that there were a few minor issues here.
One being that .Click doesn't always function properly, I would suggest using .getAttribute("href") combined with ie.Navigate()
Another being that you seem to define html then never use it again.
The following code works:
Sub test()
Dim ie As InternetExplorer
Dim html As HTMLDocument
Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "http://beverlyhills.yourkwoffice.com/mcj/user/AssociateSearchSubmitAction.do?orgId=5058&lastName=&firstName=&rows=100"
Do While ie.READYSTATE <> READYSTATE_COMPLETE
DoEvents
Loop
Set html = ie.Document
Set objA = html.getElementsByClassName("website")(0).getElementsByTagName("a")(0)
ie.Navigate (objA.getAttribute("href"))
End Sub

Automatically uploading a picture file to a free online OCR resource

I am trying to upload a .jpg file to a free online OCR site. I am using Excel VBA for this project:
Sub getOcrText()
Dim ocrAddress As String: ocrAddress = "http://www.free-online-ocr.com"
Dim picFile As String: picFile = "C:\Users\310217955\Documents\pdfdown\test.jpg"
Dim elementCollection As Variant
Dim IE As New InternetExplorerMedium
With IE
.Visible = True
.Navigate (ocrAddress)
Do While IE.Busy: DoEvents: Loop
Set elementCollection = IE.document.getElementsByName("fileUpload")
End With
IE.Quit
Set IE = Nothing
End Sub
However, when I run the code to see whether I get objects to elementCollection I get a Runtime error, automation error, unspecified error, the code successfully navigates to the desired webpage.
How do I overcome this error?
You need to change a couple lines.
First this one:
Dim IE As Object: Set IE = CreateObject("InternetExplorer.Application")
.
The second problem...
IE.Busy is not a sufficient test. Make that line the following instead:
Do While (IE.Busy Or IE.READYSTATE <> 4): DoEvents: Loop

Excel VBA "Method 'Document' of object 'IWebBrowser2' failed"

I'm trying to automate a form submission in Excel for work, and In have trouble with the basics. I keep getting the error message:
"Method 'Document' of object 'IWebBrowser2' failed"
With the code as is, and if I include the Or part in the waiting check, I get the error
"Automation Error The object invoked has disconnected from its clients."
I'm not sure what to do here, I've searched all over for solutions. This code is intended to eventually do more than this, but it keeps failing on the first try to getElementsByTagName.
Sub GoToWebsiteTest()
Dim appIE As Object 'Internet Explorer
Set appIE = Nothing
Dim objElement As Object
Dim objCollection As Object
If appIE Is Nothing Then Set appIE = CreateObject("InternetExplorer.Application")
sURL = *link*
With appIE
.Visible = True
.Navigate sURL
End With
Do While appIE.Busy ' Or appIE.ReadyState <> 4
DoEvents
Loop
Set objCollection = appIE.Document.getElementsByTagName("input")
Set appIE = Nothing
End Sub
I ran into this same issue a while back. Use internet explorer at a medium integrity level. InternetExplorer defaults to a low integrity level which, if you are doing this over a local intranet at work, sometimes will give the second error message you show above.
Click here for more reading on this. I've modified your code below. Please let me know if that helps.
Sub GoToWebsiteTest()
Dim appIE As InternetExplorerMedium
'Set appIE = Nothing
Dim objElement As Object
Dim objCollection As Object
Set appIE = New InternetExplorerMedium
sURL = "http://example.com"
With appIE
.Navigate sURL
.Visible = True
End With
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set objCollection = appIE.Document.getElementsByTagName("input")
Set appIE = Nothing
End Sub
Remember references for Microsoft Internet Controls, and depending on what you plan on doing further, Microsoft HTML Object Library
Not exactly same as above code but somehow similar , the following code solved my problem:
Do
Loop Until ie.readystate = 3
Do
Loop Until ie.readystate = 4
Just put it before the line you want to start working with the contents.
To get more information about how does it work you can check here
The below method solved my problem for this error:
Close all the explorer instances through 'Task manager' and try to run the code it will work.