Help Needed with VBA to Copy Data From Active Cell in worksheet and paste into search bar from webpage

BHuffXLnovice

Board Regular
Joined
May 15, 2015
Messages
54
Hi,

Simply put, I'm trying to put together code that will copy and paste an active cell's data into a specific search box on a webpage.

Here is what I have so far. This opens the webpage but then nothing happens from there. I get an "Object Required" message within excel.

The webpage contains two search boxes. I'm looking to copy and paste the active cell data into the second search box but am unsure how to refer to it. The code that I'm using was found online.

I'm thinking there might be an issue with "Delay 1" and also with how the code refers to the search box but I'm not sure how to resolve this. Any help that can be provided would be appreciated. Thanks!

Code:
Dim IE As Object

Sub SICsearch()


    Application.ScreenUpdating = False


    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.Navigate "http://siccode.com/en/siccode/list/lookup"


    Application.StatusBar = "Submitting"
    ' Wait while IE loading...
    While IE.Busy
        DoEvents
        ActiveCell.Select
        Selection.Copy
    Wend
    ' **********************************************************************
    delay 1
        IE.Document.getElementById("Search").Value = ActiveCell.Value
    delay 1
        IE.Document.getElementById("Search").Paste
    delay 2
        IE.Document.getElementById("Search").Click
    '**********************************************************************


End Sub


Private Sub delay(seconds As Long)
    Dim endTime As Date
    endTime = DateAdd("s", seconds, Now())
    Do While Now() < endTime
        DoEvents
    Loop
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Okay, so I just figured out the answer to the search bar name. The code is now taking me to the webpage and then copying and pasting the activecell data into the search field. The only issue is that the "click" code is not triggering the search button on the webpage - I get an error message that reads "object doesn't support this property or method". Any help that can be provided here would be appreciated. Here is the revised code:

Code:
Dim IE As Object

Sub SICsearch()


    Application.ScreenUpdating = False


    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.Navigate "http://siccode.com/en/siccode/list/lookup"


    Application.StatusBar = "Submitting"
    ' Wait while IE loading...
    While IE.Busy
        DoEvents
        ActiveCell.Select
        Selection.Copy
    Wend
    ' **********************************************************************
    delay 1
        IE.Document.getElementById("search_keyword").Value = ActiveCell.Value
    delay 1
        IE.Document.getElementById("search_keyword").Paste
    delay 2
        IE.Document.getElementById("search_keyword").Click
    '**********************************************************************


End Sub


Private Sub delay(seconds As Long)
    Dim endTime As Date
    endTime = DateAdd("s", seconds, Now())
    Do While Now() < endTime
        DoEvents
    Loop
End Sub
 
Upvote 0
Hi,
I was unaware that posting to a different site would create an issue. I now have cross post labels on both sites, which cancel out any chance of getting a response.

I posted on two different sites to try and improve the likelihood of getting a response, not realizing that the same users would be on each site. My apologies for the confusion here, but are there any recommendations as to how to resolve this? Am I able to delete this thread from this site and just rely on the other or vice versa?
 
Upvote 0

Forum statistics

Threads
1,215,493
Messages
6,125,128
Members
449,206
Latest member
burgsrus

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