Excel Error 438 Object Doesn't Support property or Method

kdenney

Board Regular
Joined
Apr 26, 2010
Messages
103
I am trying to use the below code to go a specific website and cause a
dropdown to fire. But it is giving a error 438 object doesnt support this property or method at the With appIE.document.frmNavigation spot in the code. Any suggestions?


Sub PropInfo()
Dim appIE As SHDocVw.InternetExplorer
Set appIE = New SHDocVw.InternetExplorer
'Set appIE = CreateObject("INTERNETEXPLORER.APPLICATION")
appIE.Visible = True
appIE.navigate "http://gisims2.miamidade.gov/MyHome/proptext.asp"

Do While appIE.Busy: DoEvents: Loop
Do While appIE.readyState <> 4: DoEvents: Loop

With appIE.document.frmNavigation
.Item("bytool").Value = "ADDR" 'Search by' dropdown
' .Item("bytool").selectedIndex = 1 'an alternative to setting the value
directly
.Item("bytool").onchange 'should fire the event handler on the select
'etc .submit
End With
End Sub
 
I take it there's no way you can post a URL for the intranet site?

Without that it's kind of hard to help with this sort of thing.

Every page is designed differently and it's quite hard to generalise about this sort of thing.

Looking at the code I think the problem is that there is no object called frmNavigation on the 'real' page you want to use this code on.

If you can take a look at the source code of the page and in particular look out for any id attributes.

With an id you can use GetElementByID to create a reference to a control/form/anything really on the page - if it's got an idea of course.

The following code creates references for the document, form and dropdown.

It then picks the 2 item ('Address', index 1) from the dropdown and triggers it's onchange event.

Rich (BB code):
Option Explicit
 
Sub PropInfo()
Dim appIE As Object
Dim doc As Object
Dim frmNav As Object
Dim ddTool As Object
Dim btnSubmit As Object
 
    Set appIE = CreateObject("INTERNETEXPLORER.APPLICATION")
 
    appIE.Visible = True
 
    appIE.navigate "http://gisims2.miamidade.gov/MyHome/proptext.asp"
 
    Do While appIE.Busy: DoEvents: Loop
 
    Do While appIE.readyState <> 4: DoEvents: Loop
 
    Set doc = appIE.document
 
    Set frmNav = doc.getelementbyid("frmnavigation")  
    Set ddTool = doc.getelementbyid("bytool")
 
    ddTool.selectedindex = 1
 
    ddTool.onchange
 
    Set appIE = Nothing
 
End Sub
If you take a look at the source of the actual page you are interested in perhaps this will give you some pointers.

By the way I don't know how but this worked even though there weren't any id attributes for the form etc, GetElementByID seemed to work
with the names.:eek:

PS No references required.

I am trying to find out what the above boldened line of code : Set frmNav = doc.ElementId(frmnavigation) actually does or how I replace it with something in the HTML of the page I need. Unfortunately I cannot post the website URL as it is prioprietary to my company. Thank you!
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Also that code HTML doesn't have a postback command on the onchange event in the case of my website. Do we know of any way to get around that?
 
Upvote 0
ddTool.selectedIndex = 2
This line of command is coming back with the Run Time Error 91 Object Variable or With Variable Not Set
 
Upvote 0
The bolded line is meant to set a reference to the form.

On the page the URL you posted points to it's called 'frmNavigation' - it could, and probably is different on your intranet.

As for a 'postback' command, I'd just say to sort of forget about that.

Whatever that is/does is probably being driven by an event on the page, eg the onchange event of a dropdown.

Whatever code an event triggers you can trigger by basically triggering the event.

Sort of like mimicking doing it manually.

How exactly are you running the code I posted and with what URL/page?

The error you describe could be caused by a number of things.
 
Upvote 0
Well, the code you gave me works for any html page that does not have a postback command with the onchange event (I knew that is what it is tied to because I talked to the guy that developed the web page). My question is how do I get it to fire the postback onchange event. A regular onchange event is easier to do of course and I have done it but when it is associated with the HTML script to do a postback I don't know the VBA language to mimic that.
 
Upvote 0
The bolded line is meant to set a reference to the form.

On the page the URL you posted points to it's called 'frmNavigation' - it could, and probably is different on your intranet.

As for a 'postback' command, I'd just say to sort of forget about that.

Whatever that is/does is probably being driven by an event on the page, eg the onchange event of a dropdown.

Whatever code an event triggers you can trigger by basically triggering the event.

Sort of like mimicking doing it manually.

How exactly are you running the code I posted and with what URL/page?

The error you describe could be caused by a number of things.

I guess I am sort of confused because I know that the code you posted in theory still causes an onchange event to fire however when I modified that code to reflect my elementID's etc. it still gave me the bugged out error.
 
Upvote 0
Sub PropInfo()
Dim appIE As Object
Dim doc As Object
Dim frmNav As Object
Dim ddTool As Object
Dim btnSubmit As Object

Set appIE = CreateObject("INTERNETEXPLORER.APPLICATION")

appIE.Visible = True

appIE.navigate "CompanyURL"
Do While appIE.Busy: DoEvents: Loop

Do While appIE.ReadyState <> 4: DoEvents: Loop

Set doc = appIE.document

'Set frmNav = doc.getElementById("frmnavigation")

Set ddTool = doc.getElementById("xldropdown")

ddTool.selectedIndex = 2

ddTool.onchange

Set appIE = Nothing

End Sub

As You can see I used the same code and just commented out the frmnav line simply because my HTML doesn't have that then I inserted my elementID in the ddTool field and changed the website and it still wouldn't work. Accordingly I would think it would simply because it still fires an onchange event according to the code but it simply doesn't do it on the page.
 
Upvote 0
What do you mean by a postback command?

Something like this?
Rich (BB code):
<TABLE class=formattedsourcecode cellSpacing=0 cellPadding=0><TBODY><TR><TD class=content><!-- </TD></TR><TR bgColor=#f5f5f5><TD class=linenumber>11</TD><TD class=content>function __doPostBack(eventTarget, eventArgument) { </TD></TR><TR><TD class=linenumber>12</TD><TD class=content>    var theform = document.myForm; </TD></TR><TR bgColor=#f5f5f5><TD class=linenumber>13</TD><TD class=content>    theform.__EVENTTARGET.value = eventTarget; </TD></TR><TR><TD class=linenumber>14</TD><TD class=content>    theform.__EVENTARGUMENT.value = eventArgument; </TD></TR><TR bgColor=#f5f5f5><TD class=linenumber>15</TD><TD class=content>    theform.submit(); </TD></TR><TR><TD class=linenumber>16</TD><TD class=content>} </TD></TR><TR bgColor=#f5f5f5><TD class=linenumber>17</TD><TD class=content>// --></EM></SPAN></EM></SPAN></TD></TR></TBODY></TABLE>

Does the onchange event of the dropdown call a function similar to this?

The code I posted, or similar, should work with pages that use postback to send requests to a database and return data.

The only reason I included the onchange part was because you mentioned postback and for seem to have to trigger it manually with these types of pages.

For a 'normal' dropdown you usually don't need to actually call/trigger the onchange explicitly in the code.

There is another thing you could try which, checking the document is ready.
Rich (BB code):
 Do While appIE.ReadyState <> 4: DoEvents: Loop
 
Set doc = appIE.document
 
Do While doc.ReadyState <> "complete": DoEvents: Loop
 
Upvote 0
Norie, your code didnt post but it relatively looks like this:

.onchange(_doPostback...)

Can you re-create the original code with that new code snippet you added? Thanks for your help it is much needed.
 
Upvote 0

Forum statistics

Threads
1,225,553
Messages
6,185,626
Members
453,309
Latest member
window15

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