Help with Sendkeys or alternate method to enter data in website

dpiche

New Member
Joined
Jun 14, 2010
Messages
1
Hello,
In Excel 2007, I'm trying to get data from a website using VBA so that I can process it.
I have to enter the website and enter in a part number to search on, then select the search result. Finally, I can highlight everything and copy to the clipboard. From there, I can work out the steps in the code to process the data.

Since the website does not change the URL based on my input, I haven't been able to just get the data directly from the website.

I was able to use the Sendkeys command to automate this process, but the results are erratic. For example, I have to tab 14 times on the first operation and 20 times on the second operation to select the right box. The first problem is that it doesn't always end up in the right place- sometimes passes the desired box. The second problem occurs when entering the part number (done as a single string)- sometimes the characters are repeated, like a stuck key (maybe the same problem as with the tabs).

I'm already using the "True" optional operator after the Sendkeys command to ensure the command is accepted before continuing. I don't see an option to select the time the key is depressed.

Any ideas would be appreciated.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi
Welcome to the Board

Do not use SendKeys - use DOM

Code:
Sub test()
    On Error Resume Next
    Set IE = CreateObject("InternetExplorer.Application"): DoEvents
    NavStr = "https://server_name/template.cgi?tpl=base/index.tpl"
    'IE.Visible = -1

    IE.Navigate NavStr

    While IE.busy Or (IE.readyState <> 4): DoEvents: Wend
    Set ieDoc = IE.Document

    With ieDoc.frames.Item(0).Document
        .all("search").Value = "SearchString"
        .forms("frm_param").submit ' start search
    End With

    While IE.busy Or (IE.readyState <> 4): DoEvents: Wend

    Set t = ieDoc.frames.Item(1).Document.activeElement.childNodes(1)

    For i = 1 To t.Rows.Length - 2
        With t.Rows.Item(i).Cells
            ' your code here
        End With
    Next i

    IE.Quit
    Set IE = Nothing
End Sub

Code:
Sub test()
    On Error Resume Next
    Set IE = CreateObject("InternetExplorer.Application"): DoEvents
    NavStr = "https://server_name/address"
    IE.Navigate NavStr

    While IE.busy Or (IE.readyState <> 4): DoEvents: Wend
    Set ieDoc = IE.Document

    With ieDoc
        .all("login").Value = "YourLoginHere"
        .all("password").Value = "YourPasswordHere"
        .forms(0).submit
    End With
    While IE.busy Or (IE.readyState <> 4): DoEvents: Wend

    MsgBox ieDoc.body.innerText, vbInformation, "page text"
    IE.Quit
    Set IE = Nothing
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,713
Messages
6,174,043
Members
452,542
Latest member
Bricklin

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
Back
Top