• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Passing string to web page field (box)

Jack

Member
Hi all

I am trying to pass a search string a user enters to my Google Custom Search Engine (GCSE) https://www.google.com/cse/publicurl?cx=012611895431513734681:xpw195-soo8 . It used to be easy as the search string became part of the URL so I used followhyperlink happily. But these days the GCSE URL stays the same post searching. So effectively the web page is brought up and the text has to go to the right box. Sounds easy right? But I am struggling on this one.

Below is what I have been experimenting with but it falls over at 3rd last line. I don't think I have got the getelementsbyname form names right which I got using Firefox's right click inspect elements

Can anyone shine a light on this topic for me?

Also say you want to have the option of using Firefox not IE?
regards
John

Sub OpenPage()
Dim ie As InternetExplorer
Set ie = New InternetExplorer
ie.Navigate "https://www.google.com/cse/publicurl?cx=012611895431513734681:xpw195-soo8"
While ie.Busy
Wend
ie.Document.getElementsByName("gsc-control-cse").Item.innerText = "help"
ie.Document.getElementsByName("gsc-search-button").Item.Click ie.Visible = True
End Sub
 
Hi,​
unnecessary to pilot IE to achieve this​
but - like I just did - read the Google CSE help to see its arguments …​
Found in less than one minute ‼​
Check this :​
Code:
Sub Demo()
    Const S$ = "apply conditional formatting"
 
    ThisWorkbook.FollowHyperlink "https://www.google.com/cse/publicurl?q=" & _
                                Join(Split(S), "+") & "&cx=012611895431513734681:xpw195-soo8"
End Sub
Works either with Firefox …​
Enjoy !​
 
@Marc L
Thanks very much works perfectly! I must confess I started at the Google CSE help but didn't know enough about how HTML or Java etc worked and so my eyes glazed over and further Googling led me to this other approach. Would you mind cutting and pasting the bit from Help that told you this so I can learn how to search better in the future?

I will still watch out for info or articles on passing a string to any given website input field as it would be handy to understand this area situations like entering say a currency and date to a fx conversion site or for logging in to websites.

But thanks so much again and this post should be marked solved somehow.
Cheers
John
 
Longer to write it than to find it ! Well, start with the Google Search Engine page,​
at the bottom click on developer documentation.​
On the new page in the chapter Resources and tools click on Test Your Linked CSE,​
on the new page click the link see the documentation to enter the page​
Linked Custom Search Engines : parameters are inhere, q for the Query box …​
And you can also see the command line after trying the search engine box …​
 
OK Marc L appreciate this very much and sorry to put you to more effort but I just want to understand this stuff better. Never had anything to do with XML before and was not even getting a hand hold on the learning curve. On the Test and troubleshoot your Linked CSE page - what is the xml version of my CSE that you entered? I tried adding .xml to the public URL but it says its in error.
thanks and cheers
 
No worries Marc I was just trying to figure out how you got the URL from what I was seeing but hats off to you, it is great to have the functionality I wanted.
Cheers
John
 
Back
Top