Hi all,
Long time browser of this site and others. Been slowly picking up some vba skills by reading others questions online. After over a year of doing this, I've finally ran into a situation where I can't get something to work after many hours looking online and trying many things. Hoping I'm just missing a couple key lines that will get me where i need to be.
My goal:
My job requires us to track our billable hours. This is done on a website. I have already developed a macro to collect data throughout the day and print off a timesheet that is ready for entry into the website. My next step is to try and automate this process. The below code runs on my system without errors. It opens the page (it is firm intranet, so I have removed the URL) and tries to cylce through fields on the page and print the contents. Problem is that is returns nothing. Ultimately, once I can get it to actually find the fields and manipulate their contents, I can write the code myself to put the correct information in the fields.
I have also provided a snippet of how the data is presented in the html of the website, in hopes that my methodology is wrong with regards to accessing it.
The core of my question is this: How can I access each tr item and potentially manipulate its contents?
HTML sample of stuff I'm trying to get at. Look near the far right for the exact stuff I'm trying to pull (STUFF I WANT). This is only the top bit of the table but hopefully this is a good enough snippet to see what method to use.
Long time browser of this site and others. Been slowly picking up some vba skills by reading others questions online. After over a year of doing this, I've finally ran into a situation where I can't get something to work after many hours looking online and trying many things. Hoping I'm just missing a couple key lines that will get me where i need to be.
My goal:
My job requires us to track our billable hours. This is done on a website. I have already developed a macro to collect data throughout the day and print off a timesheet that is ready for entry into the website. My next step is to try and automate this process. The below code runs on my system without errors. It opens the page (it is firm intranet, so I have removed the URL) and tries to cylce through fields on the page and print the contents. Problem is that is returns nothing. Ultimately, once I can get it to actually find the fields and manipulate their contents, I can write the code myself to put the correct information in the fields.
I have also provided a snippet of how the data is presented in the html of the website, in hopes that my methodology is wrong with regards to accessing it.
The core of my question is this: How can I access each tr item and potentially manipulate its contents?
Code:
Option Explicit
Sub ParseTable()
Dim i As Integer
Dim j As Integer
Dim IE As InternetExplorer
Dim HTMLdoc As MSHTML.IHTMLDocument 'Document object
Dim eleColtr As MSHTML.IHTMLElementCollection 'Element collection for tr tags
Dim eleColtd As MSHTML.IHTMLElementCollection 'Element collection for td tags
Dim eleRow As MSHTML.IHTMLElement 'Row elements
Dim eleCol As MSHTML.IHTMLElement 'Column elements
Dim ieURL As String 'URL
Dim td As MSHTML.IHTMLElementCollection
Dim tr As MSHTML.IHTMLElementCollection
Dim trObj As MSHTML.HTMLGenericElement
Dim tdObj As MSHTML.HTMLGenericElement
Dim x As String
'Open InternetExplorer
Set IE = New InternetExplorerMedium
IE.Visible = True
'Navigate to webpage
ieURL = "URL HERE"
IE.Navigate ieURL
'Wait
Do While IE.Busy Or IE.ReadyState <> 4
DoEvents
Loop
Set HTMLdoc = IE.Document 'Document webpage
Set tr = HTMLdoc.getElementsByTagName("TR")
For Each trObj In tr
Set td = trObj.getElementsByTagName("TD")
For Each tdObj In td
'do something with each td object'
x = tdObj.innerText
Next
Next
End Sub
HTML sample of stuff I'm trying to get at. Look near the far right for the exact stuff I'm trying to pull (STUFF I WANT). This is only the top bit of the table but hopefully this is a good enough snippet to see what method to use.
HTML:
<tbody style="height:100%"><tr id='ctl00xcontentPHxgrdTimesheet_r_0' style='height:1px;'><td iDV="False" class="ig_c482690d_r1 gridViewOddRow BorderGray" style="color:#339933;"><nobr><input type='checkbox' onpropertychange='igtbl_chkBoxChange(event,"ctl00xcontentPHxgrdTimesheet");' tabindex='-1' /></nobr></td><td class="ig_c482690d_r1 gridViewOddRow BorderGray" style="color:#339933;display:none;"><nobr> </nobr></td><td class="ig_c482690d_r1 gridViewOddRow BorderGray ig_c482690d_rc13" style="color:#339933;">
<img id="imgSearch" ***********="this.style.cursor='hand'" *******="return beginEditTemplate2();"
**********="this.style.cursor='default'" src="../NS/Images/Lookup.gif" />
</td><td class="ig_c482690d_r1 gridViewOddRow BorderGray ig_c482690d_rc14" style="color:#339933;display:none;"><nobr>Regular Time</nobr></td><td class="ig_c482690d_r1 gridViewOddRow BorderGray ig_c482690d_rc15" style="color:#339933;"><nobr>STUFF I WANT</nobr></td><td class="ig_c482690d_r1 gridViewOddRow BorderGray ig_c482690d_rc16" style="color:#339933;"><nobr>STUFF I WANT</nobr></td>