メインコンテンツへスキップ

Googleの検索結果をExcelのワークシートに入力するにはどうすればよいですか?

場合によっては、Googleで重要なキーワード検索を実行し、記事のタイトルとハイパーリンクを含むワークシートに上位の検索結果レコードを保持する必要があります。 この記事では、セル内の特定のキーワードに基づいてGoogle検索結果をワークシートに入力するのに役立つVBAメソッドを提供します。

Googleの検索結果をVBAコードでワークシートに入力します


Googleの検索結果をVBAコードでワークシートに入力します

以下のスクリーンショットに示すように、列Aのリストを検索する必要があるキーワードを想定して、次のようにして、これらのキーワードのGoogle検索結果を対応する列にVBAコードで入力してください。

1。 プレス 他の + F11 キーを押して アプリケーション向け Microsoft Visual Basic 窓。

2。 の中に アプリケーション向け Microsoft Visual Basic ウィンドウをクリックしてください インセット > モジュール。 次に、VBAコードをコピーしてコードウィンドウに貼り付けます。

VBAコード:Google検索結果をワークシートに入力します

Sub xmlHttp()
'Updated by Extendoffice 2018/1/30
    Dim xRg As Range
    Dim url As String
    Dim xRtnStr As String
    Dim I As Long, xLastRow As Long
    Dim xmlHttp As Object, xHtml As Object, xHtmlLink As Object
    On Error Resume Next
    Set xRg = Application.InputBox("Please select the keywords you will search in Google:", "KuTools for Excel", Selection.Address, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    xLastRow = xRg.Rows.Count
    Set xRg = xRg(1)
    For I = 0 To xLastRow - 1
        url = "https://www.google.co.in/search?q=" & xRg.Offset(I) & "&rnd=" & WorksheetFunction.RandBetween(1, 10000)
        Set xmlHttp = CreateObject("MSXML2.serverXMLHTTP")
        xmlHttp.Open "GET", url, False
        xmlHttp.setRequestHeader "Content-Type", "text/xml"
        xmlHttp.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0"
        xmlHttp.send
        Set xHtml = CreateObject("htmlfile")
        xHtml.body.innerHTML = xmlHttp.ResponseText
        Set xHtmlLink = xHtml.getelementbyid("rso").getelementsbytagname("H3")(0).getelementsbytagname("a")(0)
        xRtnStr = Replace(xHtmlLink.innerHTML, "<EM>", "")
        xRtnStr = Replace(xRtnStr, "</EM>", "")
        xRg.Offset(I, 1).Value = xRtnStr
        xRg.Offset(I, 2).Value = xHtmlLink.href
    Next
    Application.ScreenUpdating = True
End Sub

3。 プレス F5 コードを実行するためのキー。 ポップアップで Kutools for Excel ダイアログ ボックスで、検索するキーワードを含むセルを選択し、 OK ボタン。 スクリーンショットを参照してください:

次に、タイトルやリンクを含むすべての検索結果が、キーワードに基づいて対応する列セルに入力されます。 スクリーンショットを参照してください:


関連記事:

最高のオフィス生産性向上ツール

🤖 Kutools AI アシスタント: 以下に基づいてデータ分析に革命をもたらします。 インテリジェントな実行   |  コードを生成  |  カスタム数式の作成  |  データを分析してグラフを生成する  |  Kutools関数を呼び出す...
人気の機能: 重複を検索、強調表示、または識別する   |  空白行を削除する   |  データを失わずに列またはセルを結合する   |   数式なしのラウンド ...
スーパールックアップ: 複数の基準の VLookup    複数の値の VLookup  |   複数のシートにわたる VLookup   |   ファジールックアップ ....
詳細ドロップダウン リスト: ドロップダウンリストを素早く作成する   |  依存関係のドロップダウン リスト   |  複数選択のドロップダウンリスト ....
列マネージャー: 特定の数の列を追加する  |  列の移動  |  Toggle 非表示列の表示ステータス  |  範囲と列の比較 ...
注目の機能: グリッドフォーカス   |  デザインビュー   |   ビッグフォーミュラバー    ワークブックとシートマネージャー   |  リソースライブラリ (自動テキスト)   |  日付ピッカー   |  ワークシートを組み合わせる   |  セルの暗号化/復号化    リストごとにメールを送信する   |  スーパーフィルター   |   特殊フィルター (太字/斜体/取り消し線をフィルター...) ...
上位 15 のツールセット12 テキスト ツール (テキストを追加, 文字を削除する、...)   |   50+ チャート 種類 (ガントチャート、...)   |   40+ 実用的 (誕生日に基づいて年齢を計算する、...)   |   19 挿入 ツール (QRコードを挿入, パスから画像を挿入、...)   |   12 変換 ツール (数字から言葉へ, 通貨の換算、...)   |   7 マージ&スプリット ツール (高度な結合行, 分割セル、...)   |   ... もっと

Kutools for Excel で Excel スキルを強化し、これまでにない効率を体験してください。 Kutools for Excelは、生産性を向上させ、時間を節約するための300以上の高度な機能を提供します。  最も必要な機能を入手するにはここをクリックしてください...

説明


Officeタブは、タブ付きのインターフェイスをOfficeにもたらし、作​​業をはるかに簡単にします

  • Word、Excel、PowerPointでタブ付きの編集と読み取りを有効にする、パブリッシャー、アクセス、Visioおよびプロジェクト。
  • 新しいウィンドウではなく、同じウィンドウの新しいタブで複数のドキュメントを開いて作成します。
  • 生産性を 50% 向上させ、毎日何百回もマウス クリックを減らすことができます!
Comments (6)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
This code requires you to buy and download Kutools to make this code run successfully. Has anyone found an option without the Kutools add-in?
This comment was minimized by the moderator on the site
Hi Mat,There is no relationship between Kutools and the code. You don't need to download or buy Kutools, just apply the code step-by-step as mentioned in the post.
This comment was minimized by the moderator on the site
Hi Crystal

Sorry but I got an "Object Variable not set" on line 24
This comment was minimized by the moderator on the site
The same here.

I follow the code, by copy it then paste the code in Excel VBA module. But after running, nothing happen, column B and C still empty but there is no error though.
This comment was minimized by the moderator on the site
Hi, I've followed the points to be able to pull information from a google search based on keywords and it's not bringing any results though, I've emailed support and I've been advised to put a post here because they can't help me.
This comment was minimized by the moderator on the site
I have not been able to pull anything from google either. I followed instructions exactly.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations