I'm trying to use excel to automate the value entering in a time sheet. The time sheet is on a web page.
Right now I'm able to load the page, enter my username and password and then entering the time sheet by itself. See code below.
At this point I need to click on a button to open sub-forms. I can't know in advance how many sub-forms there will be to open. I know how to click on a button when it has a "name". But in this case there's none. So my updated code below use a loop to open every other subform. It works the first time, but when I do it again
Could someone point me how to determine how many of those button there is in the page and how to click on each?
Following I'm placing the code I have until now and below it, the HTML code of the page I need to interact with.
Private Sub time_sheet_filling()
Dim I As Long
Dim IE As Object
Dim doc As Object
Dim objElement As Object
Dim objCollection As Object
' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
' Send the form data To URL As POST binary request
IE.navigate "http://timesheet.cccc.ca/timesheet/"
' Wait while IE loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
'Load the logon page
Set objCollection = IE.Document.getElementsByTagName("input")
I = 0
While I < objCollection.Length
If objCollection(I).Name = "txtUserName" Then
' Set text to enter
objCollection(I).Value = "6666"
End If
If objCollection(I).Name = "txtPwd" Then
' Set text for password
objCollection(I).Value = "password"
End If
If objCollection(I).Type = "submit" And objCollection(I).Name = "btnSubmit" Then ' submit button clicking
Set objElement = objCollection(I)
End If
I = I + 1
Wend
objElement.Click ' click button to load the form
' Wait while IE re-loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
' Show IE
IE.Visible = True
Dim links, link
Dim n, j
Set links = IE.Document.getElementById("dgTime").getElementsByTagName("a")
n = links.Length
For j = 0 To n - 1 Step 2
links(j).Click
'I have some operations to be done will post another question for this
IE.Document.getElementById"DetailToolbar1_lnkBtnSave").Click 'save
IE.Document.getElementById"DetailToolbar1_lnkBtnCancel").Click 'close
Next
End Sub
So extract of the html code is below. I'm trying to click the button that is coded in the last line of the html code below
<table width="984" class="Grid" id="dgTime" border="1" rules="all" cellspacing="0">
<tbody>
<tr class="GridHeader">
</tr>
<tr class="GridItem">
</tr>
<tr class="GridItem">
<td class="GridButtonColumn">
<a href="javascript:__doPostBack('dgTime$_ctl2$_ctl0','')">
<img src="images/toolbar/b_edit.gif">
</a>
</td
Tx Tim for the answers. Now I'm able to select the first subform button to open it.
links(j).click 'j = 0
I then save it, close, and come back to the main form. But then when I try to do
links(j).click 'j = 2 this time
the second time I get a runtime error 70: permission denied. Anymore kind help will be so appreciated.
Regards
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…