Error 91 Excel VBA IE

van_ina62

New Member
Joined
Dec 28, 2019
Messages
4
Office Version
  1. 2013
  2. 2007
Platform
  1. Windows
I have this procedure to insert value to IE form but not working. The procedure is

Sub InsertValue()

Dim IE As Object
Dim doc As HTMLDocument
Dim objShell As Object

Dim str_val1 As HTMLInputElement


Dim i, A As Double
marker = 0
Set objShell = CreateObject("Shell.Application")
Dim btnGo As Object
Dim frm As Object
Dim test As Worksheet
Set test = ActiveSheet
Dim dom_tags As Object
Dim tag As Object
Set IE = CreateObject("InternetExplorer.Application")

y = 65


Application.Wait (Now + TimeValue("00:00:02"))


Set objAllWindows = objShell.Windows
IE_count = objShell.Windows.Count
For Each ow In objAllWindows
If (InStr(1, ow, "Internet Explorer", vbTextCompare)) Then

test.Range("A" & y) = ow
test.Range("B" & y) = ow.hwnd
test.Range("C" & y) = ow.document.Title
test.Range("D" & y) = ow.LocationURL
y = y + 1


If test.Cells(y - 1, 3).Value Like "Legal of - " & "*" Then

Set IE = objShell.Windows((y - 65))
Set doc = IE.document
marker = 1
Exit For
Else
End If
End If
Next


If marker = 0 Then
MsgBox ("A matching webpage was NOT found")

Else
MsgBox ("A matching webpage was found")

Set str_val1 = doc.getElementById("fieldName:COLLATERAL.TYPE")
str_val1.Value = test.Cells(i + 2, 12).Value <===================error 91

End If
End Sub

so many thanks for help this problem
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi,

Are you sure the error does not appear on the line above the one you highlighted? i.e. Set str_val1 ?

I suspect the object variable cannot be set (error 91) because you didn't navigate to the webpage. With InternetExplorer object, you need to first open the webpage (you can set .Visible = False if you don't want to see the webpage) and then you can look for a specific element. Try testing something like that:

VBA Code:
With IE

    .Visible = True

    .Navigate "http://google.com"

    Set doc = .document

End With

Set str_val1 = doc.getElementById("fieldName:COLLATERAL.TYPE")

Debug.Print str_val1.ID

If "fieldName:COLLATERAL.TYPE" element is found, the last line should properly print its ID in VBA Immediate Window. Then you can set its value to whatever you want. Hope it helps!
 
Last edited:
Upvote 0
I pass value from excel to ie page which page has opened/popup page. So i didn't navigate to url because URL not showed.
 
Upvote 0
Ahh I see what you're doing now - thanks for explaining. What happens if you do Debug.Print str_val1.ID after you do your Set str_val1 = doc.getElementById("fieldName:COLLATERAL.TYPE")? Does it properly print object's ID in Immediate Window?
 
Upvote 0
Also, would you be able to share the link to the webpage or maybe a part of HTML code?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top