Copy word and paste to browser

ExcelTheCell

Board Regular
Joined
Nov 14, 2010
Messages
158
Well i'm in deep problems and i cant find solution...

lets say i have 3 names Eric, Maria and Lorena

They are in one colume one in the row.
Eric
Maria
Lorena

How can I tell to excel to copy first name(eric) and paste it to the textbox from google.com... Then copy all results and paste them in excel? After that to go on the next name and do the same thing..

Is that possible? Or it's SF?
Chalenge of the week if you ask me, I have spend already 7days to make something and i'm still on zero ground.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Well i try to use to copy inner HTML code with developer tools from IE over VBA Excel but don't know how...

Code doesn't work at the moment it's telling me this error
User-defined type not defined

it's problem i think with this code row

Private ieBrowser As InternetExplorer


I will play a little more to se if i can win this thing
 
Upvote 0
As the code states you must add
VBE > Tools > References > Microsoft Internet Controls

I've managed to work it out by tweaking it as it did have some problems.
Rich (BB code):
Option Explicit
Private ieBrowser As InternetExplorer
Private Const sSite As String = "http://www.google.com/search?q=" ' Change this Appropriately
Private Const sProofPath As String = "C:\Users\user\Desktop" ' Path to Save Searched Pages
Sub Test()
    Check_Data_From_Google "Eric", sSite, sProofPath
End Sub
Function Check_Data_From_Google(ByRef sData As String, ByRef sReturn As String, ByRef sSavePath As String)
    'Requires Microsoft Internet Controls reference (Tools > References from code window)
    Dim sSearchString As String ' Combination of Google Search String + Data
    Dim dtStartTime As Date ' Start Time
    Dim dtCurrentTime As Date ' Current Time
    Dim iMaxWaitTime As Integer ' Maximum waiting time (in Secs)
    Dim sDocText ' WebPage as Text
    Dim sDocHTML ' WebPage as HTML
    
    On Error GoTo Err_Clearer
    ' ---------------------------------
    ' Build the Search String
    ' ---------------------------------
    sSearchString = sSite & sData
    
    ' ---------------------------------
    ' Start Time
    ' ---------------------------------
    Init_IE
    dtStartTime = Now
    iMaxWaitTime = 10 'Seconds to be waited
    ieBrowser.Navigate (sSearchString)
    
    ' ieBrowser.Visible = True
    
    
    Do While ieBrowser.ReadyState <> READYSTATE_COMPLETE 'wait for page to load
        DoEvents
        dtCurrentTime = Now
        
        ' ---------------------------------
        ' Exit Process if it is taking long time
        ' ---------------------------------
        If DateDiff("s", dtStartTime, dtCurrentTime) > iMaxWaitTime Then sReturn = "TimeOut": Exit Function
    Loop
    
    ' Assign the Webpage Results to Variable
    sDocText = ieBrowser.Document.DocumentElement.innertext
    sDocHTML = ieBrowser.Document.DocumentElement.innerhtml
    
    If InStr(sDocText, "did not match any documents") <> 0 Then
        sReturn = "NotFound"
    Else
        If InStr(1, sDocText, sData) <> 0 Then
            sReturn = "Found"
        Else
            sReturn = "NotFound"
        End If
    End If
    
    sSavePath = sProofPath & sData & ".html"
    sSavePath = ClearCharacters(sSavePath)
    
    Open sSavePath For Output As 1
    Print #1, sDocHTML
    Close #1
    Destroy_IE
    ' -----------------------------
    ' Error Handler
    ' -----------------------------
Err_Clearer:
    If Err <> 0 Then
        Err.Clear
        Resume Next
    End If
End Function
Sub Destroy_IE()
    On Error GoTo ReInit_IE
    ieBrowser.Quit
    If Not ieBrowser Is Nothing Then Set ieBrowser = Nothing
    
ReInit_IE:
End Sub
Sub Init_IE()
    On Error GoTo ReInit_IE
    Set ieBrowser = GetObject(, "InternetExplorer.Application")
    Exit Sub
ReInit_IE:
    Set ieBrowser = CreateObject("internetexplorer.application")
    Application.Wait DateAdd("n", 1, Now) ' Wait for one/Two minutes to Start the Browser
    
End Sub

Function ClearCharacters(ByVal sDirtyString As String) As String
    Dim arUnWantedCharacter(1 To 6) As String
    Dim IsClear As Boolean
    Dim i As Integer
    Dim strCleanString As String
    Dim j As Integer
    
    arUnWantedCharacter(1) = "/"
    arUnWantedCharacter(2) = "/"
    arUnWantedCharacter(3) = "?"
    arUnWantedCharacter(4) = "*"
    arUnWantedCharacter(5) = "["
    arUnWantedCharacter(6) = "]"
    
    IsClear = True
    
    strCleanString = vbNullString
    For i = 1 To UBound(arUnWantedCharacter)
        If InStr(1, sDirtyString, arUnWantedCharacter(i)) Then
            IsClear = False
            For j = 1 To Len(sDirtyString)
                If Mid$(sDirtyString, j, 1) <> arUnWantedCharacter(i) Then
                    strCleanString = strCleanString & Mid$(sDirtyString, j, 1)
                End If
            Next j
            sDirtyString = strCleanString
        End If
    Next i
    
    If IsClear = True Then strCleanString = sDirtyString
    
Finally:
    ClearCharacters = strCleanString
End Function

The bolded terms can be altered to save HTML file.
Then you must parse HTML file to get the links.
You need alot of multiple steps for this.
 
Upvote 0
Well it Exports first page of google search results for eric...
Can we change Eric to cell range that he take insert every name from the list ant take the results..

Another questinon is how can we import all html. export files to one excell sheet...

Alot of work but i will see if i can make something out of this
 
Upvote 0
Suggestion: if you're doing all that,
please learn VBA and research on Google.

I'm sorry to tell you that but it will take less time.

I know you may not have enough time but it's much better if you could code as it's very inefficient if an answerer makes one little mistake and the questioner cannot tell what went wrong or deal with it.
 
Upvote 0
well i did make a lot of research over google... i Understand VBA language...
I just need chunk of code and over 1month i will make it work... but i was hoping for help... But tnx for help
 
Upvote 0
If you insist,
Rich (BB code):
Sub Test()
  Check_Data_From_Google "Eric", sSite, sProofPath
End Sub

the red word is the word you want to search for.
Just replace that with a string that loops through the column of search words you want to browse in Google.

I'll try to help as best because what you're trying to do is actually interesting to me.

I'm sorry if I sounded very rude before, it's just that there are a lot of people who just dump the work, try it, if it doesn't work, they just come back and ask why it isn't working after 30 seconds of trying. It's as if they don't even try to learn how it works? (brain dead people much?)

I mean that's okay if they admit they don't know programming or VBA at all. but it's the people who say they know VBA and come back after 30 seconds of trying -_-;

Red fonts are the ones you should change to fit your need.
Rich (BB code):
For i = 2 To LastRow 'LastRow of the column you're searching for
    Check_Data_From_Google Range("A" & i).Value, sSite, sProofPath
Next i

Btw, it's extremely slow as it's 10 seconds to time out of the request.
 
Last edited:
Upvote 0
I have made a tweak and it works perfect:

PHP:
Dim i As Integer
    For i = 2 To Selection.CurrentRegion.Rows.Count - 1
    
    'LastRow of the column you're searching for
    Check_Data_From_Google Range("A" & i).Value, sSite, sProofPath
Next i

Only thing that is left to do is to import that multi html pages to the excel in one sheet. I will try do that with macro recorder
Btw tnx for help you really had save me a lot of time..
 
Upvote 0
Hi, ExcelTheCell.
I'm glad I could help.

Anyways, there are two ways that I could really think of.

1) Use command window to append the HTML files in ONE folder and read one HTML file and parse the tags to get the links.
Code:
copy *.HTML all.F

Note: .F extension to avoid any collision with existing files that may have the same extension.

2) Loop through each file and based on the name of its file, it will parse the HTML tags and get the links.

I think the first method may be faster but the code for parsing may be much harder to write.
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,242
Members
452,898
Latest member
Capolavoro009

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