VBA - IE automation text field input RTE 438

David44

New Member
Joined
Nov 11, 2013
Messages
13
Hi

I'm trying to Automate IE with VBA and am running into an issue I've yet to find a solution to.
My code fails to input the desired text into the text field box. I don't think the code can even find the text box I want it to, it may have someting to do with Javascript and tables. Please take a look and let me know the best method to get this done.

Here is my code.

Rich (BB code):
Sub Placer_PDF()
Dim IE As Object
Dim url As String
Dim tags As Object
Dim tagx As Object
 
'load internet explorer
Set IE = CreateObject("internetexplorer.application")
IE.Visible = True
'go to property tax website
url = "https://common3.mptsweb.com/megabyt...aspx?CN=placer&Dept=Tax&Site=Public&PG=Search "
IE.navigate url
'wait for page to load
Do
DoEvents
Loop Until IE.readystate = 4

'Input parcel # into website
IE.Document.all("idAsmt").Value = 44444
'Çlick on the submit button
For Each tagx In tags
    If tagx.Name = "Submit" Then
        tagx.Click
    End If
Next

End Sub


And here is the Website Source.

HTML:
<
 

b>b>

 
<
 
 
br/>

 
 
 
xmlversion="1.0"encoding="utf-8"?>

 
          
 
DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 
      
 
<html><head><title>Inquirytitle>******http-equiv="Content-Type"content="text/html; charset=utf-8"/><linkrel="stylesheet"href="../Placer/WebInquiry/CSS/search.css"type="text/css"/><linkrel="stylesheet"href="Placer/WebInquiry/CSS/menus-simple.css"type="text/css"/>********type="text/javascript"language="javascript">script>********type="text/javascript"language="javascript"src="../Placer/WebInquiry/jscripts/ua.js">script>********type="text/javascript"language="javascript"src="../Placer/WebInquiry/jscripts/xbDebug.js">script>********type="text/javascript"language="javascript"src="../Placer/WebInquiry/jscripts/xbDOM.js">script>********type="text/javascript"language="javascript"src="../Placer/WebInquiry/jscripts/xbStyle.js">script>********type="text/javascript"language="javascript"src="../Placer/WebInquiry/jscripts/mbsMenuTree.js">script>********type="text/javascript"language="javascript"src="../Placer/WebInquiry/jscripts/common.js">script>********language="JavaScript"src="../_ScriptLibrary/RS.HTM">script>********language="javascript">script>********type="text/javascript"language="javascript"src="Placer/WebInquiry/jscripts/webinquiry.js">script>head><body><formname="frmMain"method="post"action="Inquiry.aspx?CN=placer&DEPT=Tax&SITE=Public&PG=taxresults"><tablecellspacing="0"cellpadding="0"width="380"><trclass="title"><tdcolspan="3"><i>Tax Inquiry: Please enter search criteriai>td>tr><trclass="titleRollYear"><tdcolspan="2"align="right">

 
                    Select Roll Year 

 
                
 
td><td><selectname="rollyear"><optionvalue="c">2013 -Current Yearoption><optionvalue="p">2012 -Previous Yearoption>select>td>tr><trclass="tr3search"><tdclass="searchfield">Feeparcel #td><tdclass="searchtype"><selectname="cbfeeparcel"id="idfeeparcel"onchange=""><optionvalue="like">Begins withoption><optionvalue="endwith">Ends withoption><optionvalue="contains">Containsoption><optionvalue="=">Equal tooption><optionvalue="<>">Not equal tooption><optionvalue="<">Less thanoption><optionvalue=">">Greater thanoption>select>td><tdwidth="150"><inputclass="userinput"maxlength="24"onkeypress="js:return SubmitOnEnter(this,event)"name="idfeeparcel">input>td>tr><trclass="tr3search"><tdclass="searchfield">Assessment #td><tdclass="searchtype"><selectname="cbAsmt"id="idAsmt"onchange=""><optionvalue="like">Begins withoption><optionvalue="endwith">Ends withoption><optionvalue="contains">Containsoption><optionvalue="=">Equal tooption><optionvalue="<>">Not equal tooption><optionvalue="<">Less thanoption><optionvalue=">">Greater thanoption>select>td><tdwidth="150"><inputclass="userinput"maxlength="24"onkeypress="js:return SubmitOnEnter(this,event)"name="idAsmt">input>td>tr>table><p><inputtype="button"class="BasicButton"name="Submit"value="Submit"*******="javascript:SubmitForm();"/><inputtype="button"class="BasicButton"name="Clear"value="Clear"*******="javascript:ClearForm();"/><inputtype="hidden"name="edtargs"id="edtargs"value="?CN=placer&DEPT=Tax&SITE=Public">input>p>form>body>html>
  
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Is that with the added click?

PS The code should work using submit instead of clckind as the click is submitting the form, so they are basically doing the same thing.
 
Upvote 0
It worked with the .click included

It didn't work without it.

Isn't the name of the button "Submit"? So I would have to name it before interacting with it right?

HTML:
<input name="Submit" class="BasicButton" *******="javascript:SubmitForm();" type="button" value="Submit"/>

Next up is getting the progam to press the generated hyperlink on the next page, with the ability to submit different Assessment numbers using the same code. it looks like the hyperlink has the year 2013 in it, which I'll have to take into account, as the program needs to work next year too.

But I'm going to play around with it first and see what I can come up with.
 
Upvote 0
Is there a way to find a link with wildcards or regular expressions. So that I only need to search for links that contain the same assessment number?

This is really as seperate issue/Question. I'll try searching for it and solving it myself. If I can't figure it out it would be beter off in an new thread.


Thank you.
 
Last edited:
Upvote 0
Why not have a look at the links collection of the document and the properties of the link element?

One of those properties will be for the URL and the URL for the links contains the assesment number(s)that's been found by the search.

For example.
HTML:
https://common3.mptsweb.com/megabytecommonsite/(zmimzpfj0i3tl2bjijk4lu3d)/PublicInquiry/Inquiry.aspx?CN=placer&Dept=Tax&Site=Public&PG=TaxMain&Asmt=453-010-001-000&TY=2013
 
Upvote 0
I was able to find the link. But I'm not sure what you mean.

If a different Number was used or if it was 2014 the link would be change.

I don't know how to search for link properties. I only see the link itself.
 
Upvote 0
This code will output the URL of all the links on the results page.
Code:
Sub Placer_PDF()
Dim IE As Object
Dim url As String
Dim lnks As Object
Dim lnk As Object

    'load internet explorer
    Set IE = CreateObject("internetexplorer.application")
    IE.Visible = True
    'go to property tax website
    url = "https://common3.mptsweb.com/megabytecommonsite/(zmimzpfj0i3tl2bjijk4lu3d)/PublicInquiry/Inquiry.aspx?CN=placer&Dept=Tax&Site=Public&PG=Search"
    IE.navigate url

    'wait for page to load
    Do
        DoEvents
    Loop Until IE.readystate = 4

    'Input parcel # into website
    IE.document.all("idAsmt")(1).Value = "036-260-017-000"
    IE.document.forms(0).submit

    'wait for page to load
    Do
        DoEvents
    Loop Until IE.readystate = 4

    Do
        DoEvents
        
    Loop Until IE.document.readystate = "complete"
    
    Set lnks = IE.document.Links

    For Each lnk In lnks
        Debug.Print lnk.href
    Next lnk

End Sub
 
Upvote 0
Rich (BB code):
Sub Placer_PDF()
Dim IE As Object
Dim url As String

    'load internet explorer
    Set IE = CreateObject("internetexplorer.application")
    IE.Visible = True
    'go to property tax website
    url = "https://common3.mptsweb.com/megabyt...aspx?CN=placer&Dept=Tax&Site=Public&PG=Search"
    IE.Navigate url
    'wait for page to load
    Do
        DoEvents
    Loop Until IE.ReadyState = 4
    'Input parcel # into website
    IE.Document.all("idAsmt")(1).Value = "036-260-017-000"
    IE.Document.forms(0).submit.Click
    
    'wait for page to load
       Do
        DoEvents
       Loop Until IE.Document.ReadyState = "complete"
    
              Set doc = IE.Document
             
            doc.getElementsByTagName("A")(0).Click
                       
          
End Sub

This worked great.

We never figured out the .click mystery, but it is working as listed above on my end.

I'm using VBA in MS Excel 2010.
 
Upvote 0
I took the code home to work on and had to take the .click out of the code for it to work. (Excel 2013, Explorer 10 or 11)

My work computer is running Excel 2010 and Explorer 9.

Could IE 9 be the issue?

Also, I noticed you corrected my wait on IE section if the code

Code:
Do
        DoEvents
       Loop Until IE.Document.ReadyState = "complete"
    
              Set doc = IE.Document

this usualy just hangs on my end. After searching the web, I can't find a reliable method of waiting on webpages with javascript and frames. The best I could do is set a hard timed delay. Do you know any other methods that are more reliable?
 
Upvote 0

Forum statistics

Threads
1,216,090
Messages
6,128,765
Members
449,467
Latest member
sdafasfasdf

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