Updating a Code for web access

t01te6

Board Regular
Joined
Apr 3, 2008
Messages
93
Hey All,

So I have this code which I have copied and pasted from various threads on this site,

Code:
'Need reference to Microsoft HTML Object Library.  Select this in Tools - References in VB editor.
Option Explicit
Public Enum IE_READYSTATE
    Uninitialised = 0
    Loading = 1
    Loaded = 2
    Interactive = 3
    complete = 4
End Enum
Sub AlphaTest()
    
    Const cURL = "[URL="https://sedsh04.sedsh.gov.uk/esd/xsql/sys_getLogin.xsql"]Web Address"[/URL]
    Const cUserID = "XXXX"     'REPLACE XXXX WITH YOUR USER ID
    Const cPwd = "YYYY"        'REPLACE YYYY WITH YOUR PASSWORD
    
    Dim ie As Object
    Dim doc As HTMLDocument
    Dim PageForm As HTMLFormElement
    Dim UserIdBox As HTMLInputElement
    Dim PasswordBox As HTMLInputElement
    Dim FormButton As HTMLInputButtonElement
    Dim Elem As IHTMLElement
    
    Set ie = CreateObject("InternetExplorer.Application")
    
    ie.Visible = True
    ie.navigate cURL
    
    'Wait for initial page to load
    
    Do While ie.busy Or Not ie.readyState = IE_READYSTATE.complete: DoEvents: Loop
           
    Set doc = ie.document
    
    'Output HTML tags to debug window
    
    Debug.Print "Login page: " & ie.LocationURL
    For Each Elem In doc.all
        'Debug.Print Elem.tagName
    Next
    'Get the only form on the page
    
    Set PageForm = doc.forms(0)
          
    'Get the User Id textbox
    '< input class="TextBox" maxlength="15" name="UserName" size="12">
    
    Set UserIdBox = PageForm.elements("UserName")
    
    'Set the User Id
    
    UserIdBox.Value = cUserID
    
    'Get the password textbox
    '< input class="TextBox" type="password" maxlength="10" name="Password" size="12">
    
    Set PasswordBox = PageForm.elements("Password")
    
    'Set the password
    
    PasswordBox.Value = cPwd
    
    'Submit the form (like clicking the 'Submit' button) to navigate to next page
    
    PageForm.submit
    
    'Wait for the new page to load
    
    Do While ie.busy Or Not ie.readyState = IE_READYSTATE.complete: DoEvents: Loop
    
    'Get the HTML document of the new page
    
    Set doc = ie.document
    
    'Output HTML tags to debug window to prove this is the new page
    
    Debug.Print "Terms of Use page: " & ie.LocationURL
    For Each Elem In doc.all
        'Debug.Print Elem.tagName
    
Next
ie.Visible = True
'Send logg-on information!
'May need additional SendKeys as needed?
'Determine by the actual key-strokes needed!
SendKeys "(TAB)", True
SendKeys "{TAB}", True
SendKeys "(ENTER)", True
Application.Wait (Now + TimeValue("0:00:02"))
ActiveWindow.WindowState = xlMaximized
End Sub

Now I am wondering see at the end instead of using send keys could a code be put in which says Find words "My Clients" and click enter, then get a message box that comes up and says what client?

The name could then be entered in here which excel could find on that page and then press the select button on the same row as that client.

Does that make sense, I am now sure what the code is of asking excel to find a series of words on the website and press enter after.

Could anyone please help?

Thanks
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
L

Legacy 98055

Guest
Without the actual source HTML, it is going to be difficult to recieve any help from others. The structure of a web page is unique and, therefore, so is the code to process it.
 
L

Legacy 98055

Guest
No. The page that contains your client info. Since I am certain that you cannot post that information here, you may need to.

LogIn and navigate to the client page.
From the menu bar, not the right click menu, choose View, Source. Save the resulting text file. Find-Replace your client data with non sensative information. Post that here within html.../html tags so that I can view the source.
 
Last edited by a moderator:

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,769
The OP already had a thread on basically the same issue - http://www.mrexcel.com/forum/showthread.php?t=324416

to1te6, please stick to one thread if you can.

And that code looks familiar :)

I've been playing around trying to combine InternetExplorer automation with Excel web queries and have found a workaround. Will post in the other thread later.
 
L

Legacy 98055

Guest
I've been playing around trying to combine InternetExplorer automation with Excel web queries and have found a workaround. Will post in the other thread later.

Am interested in this... :)
 

Watch MrExcel Video

Forum statistics

Threads
1,130,329
Messages
5,641,546
Members
417,219
Latest member
FrancoisT

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
Top