this code worked in access 97 and i am getting an error on the internet explorer variable. Is there an updated way of having vba open this program?
Code:
Function getEmail(enumber As String) Dim url As String Dim IE As InternetExplorer Dim HTMLDoc As HTMLDocument Dim html As String Dim atLocation As Long, startLocation As Long, endLocation As Long Dim x As Long 'Create a new instance of Internet Explorer Set IE = Nothing Set IE = New InternetExplorer 'Define the URL we will be loading url = "http://people.aflacworkplace.com//Person.aspx?accountname=AFLHQ\" & enumber 'Ensure that the IE Window is hidden and navigate to the website defined above IE.Visible = False IE.navigate url 'Loop until the website is completely loaded... Do While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE DoEvents Loop 'Save the html behind the page we are on to a variable (html) and determine which character contains the first @ html = IE.Document.body.outerHTML atLocation = InStr(1, html, "@") 'Loop backwards from the "@" location to find the opening ":" (the E-Mail address is first listed in the html as 'email@aflac.com') For x = atLocation To 0 Step -1 If Mid(html, x, 1) = ":" Then startLocation = x + 1 Exit For End If Next 'Loop forwards from the "@" location to find the closing "'" For x = atLocation To (atLocation + 100) Step 1 If Mid(html, x, 1) = "'" Then endLocation = x Exit For End If Next 'Close IE and Destroy Object IE.Quit Set IE = Nothing 'Return Value getEmail = Mid(html, startLocation, endLocation - startLocation) End Function
Comment