1

This is not for the first time I am mentioning this...but yeah I am a rookie in vba and in need of help... I am having trouble in filling up a value in a box in webpage using vba excel.

The source code of the box is

<input
name="MultiRenameTable_OR:wt.epm.EPMDocument:3053059700_NEWNAME_JSID"
class="enabledfield"
id="MultiRenameTable_OR:wt.epm.EPMDocument:3053059700_NEWNAME_JSID"
style="WIDTH:98% onblur="setJSAttributeValue(this,'NEWNAME_JSID','MultiRenameTable', 'epmdoc_09876889_u46_drw',undefined)" type="text" size="25" ?=""
trlId="MultiRenameTable_epmdoc_09876889_u46_drw_NEWNAME_JSID"></input>

the code i wrote is

Sub xx()


Dim ie As Object
Dim doc As HTMLDocument
Dim lo As IHTMLElementCollection
Dim l As IHTMLElement

Set ie = CreateObject("internetexplorer.application")
ie.navigate "mysiteurl"
ie.Visible = True

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

Set doc = ie.document

doc.getElementById("MultiRenameTable_OR:wt.epm.EPMDocument3053059700_NEWNAME_JSID").Value = "xyz"

End Sub

It doesnt set the value. Also i cannot use "name","ID","trlID","onblur" because they keep on changing each time i launch IE. Please help me with this.

NEO
  • 23
  • 1
  • 1
  • 4

1 Answers1

1

I'm guessing from the setJSAttributeValue that the name will always contain the substring "NEWNAME_JSID". Just grab all of the input elements, then loop through them looking for it in the name:

Sub xx()

    Dim ie As Object
    Dim doc As HTMLDocument
    Dim lo As IHTMLElementCollection
    Dim l As IHTMLElement

    Set ie = CreateObject("internetexplorer.application")
    ie.navigate "mysiteurl"
    ie.Visible = True

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

    Set doc = ie.document
    Set lo = doc.getElementsByTagName("input")

    For Each l In lo
        If l.Name Like "*NEWNAME_JSID*" Then
            'Do whatever.
            Exit For
        End If
    Next l

End Sub
Comintern
  • 21,855
  • 5
  • 33
  • 80
  • Hi Comintern...I tried it but had no luck...it says object variable or block variable not defined...I had set a watch on "lo" just to check whether the element I am interested is in the collection and found it wasn't...I tried to search it under other tag names,class name...but couldn't find it....Some how I think the elements under "multi rename table" are not collectable...is there a way to collect these items?? – NEO Mar 27 '16 at 05:33
  • @NEO - getElementsByTagName("input") doesn't return anything? I'd probably have to see the full page source to figure out what's going on. Is it a publicly accessible URL? – Comintern Mar 27 '16 at 13:47
  • @Comintern...its a web page application of my company and is accesible to employees..so i may not be able to provide you the entire sourcepage.I am trying to automate a renaming process in which first i search the component and click on rename.It opens up table/form(really not sure) where i need to put new name...The source code of the table/form is – NEO Mar 27 '16 at 17:01
  • @NEO - Wow, you have to web-scrape an internal website? That's harsh. – Comintern Mar 27 '16 at 17:04
  • @Comintern..yeah it is..but it would save lot of time and to be precise unproductive hours...i have updated the post with the source code...please have a look – NEO Mar 27 '16 at 17:09
  • @NEO - There's enough missing from the sample HTML that I still can't tell everything that is going on. One other avenue that you might explore is doing an HTTP POST directly instead of trying to fill the form. – Comintern Mar 27 '16 at 17:34
  • @Cominterm.... m extremely sorry for the troulble..could you please tell me what to do when you say "doing an HTTP POST" – NEO Mar 27 '16 at 17:39
  • @NEO - No trouble at all - you basically just perform the same HTTP operation that submitting the form would do. [See this question](http://stackoverflow.com/q/158633/4088852) for an example. – Comintern Mar 27 '16 at 17:43