2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

エクセルからGoogle Adwordsの予算設定を一括で行う(Selenium VBA)

Last updated at Posted at 2015-02-28

celenium + excel + chrome の組み合わせで、GoogleAPIの[BudgetOrder]リクエストが使えなくても
代理店が各アカウントに対して毎月月末に行う、来月の月額予算設定を一括で実行する泥臭い方法。

※ループ処理、例外処理、エラーハンドラは省略、wait処理はミニマムな記述
※celenium wrapper type libralyをアーリーバインドしておく

Sub Start_BudgetOrder_with_chrome()
 Dim  driver As New SeleniumWrapper.WebDriver
 Call driver.Start("chrome", "https://accounts.google.com/ServiceLogin?")
 Call driver.get("")
 driver.findElementById("Email").SendKeys (Sheets("sheet1").Range("B4").Value)  'GoogleアカウントID
 driver.findElementById("Passwd").SendKeys (Sheets("sheet1").Range("B5").Value) 'GoogleアカウントPASS 
 driver.findElementById("gaia_loginform").submit
 
 Call driver.get("/signup?authuser=0&__c=[AccountID]&u=[agentID]" ) 'アカウントIDと代理店IDは管理画面URL内Getパラメータより事前に取得

 driver.findElementById("Passwd").SendKeys (Sheets("sheet1").Range("B5").Value) ’再度パスワードを要求されるので対応
 driver.findElementById("gaia_loginform").submit
 
 Call driver.get("https://adwords.google.com/payments/u/0/adwords/signup?authuser=0&__c=[AccountID]&u=[agentID]#MANAGE_BUDGETS")

 Dim frameUrl
 frameUrl = driver.findElementsByTagName("iframe").Item(0).getAttribute("src") ’新しい予算オーダーはiframe内なのでiframe側に移動
 driver.get frameUrl
 driver.waitForVisible ("id=addBudget") ’AJAX処理を待つ
 
 driver.Click "id=addBudget"

 Dim collection2 As WebElementCollection
 Set collection2 = driver.findElementsByClassName("jfk-radiobutton-radio")
 
 driver.Click "id=fixedSpendingLimitAmount.amountInput"
 driver.Type "id=fixedSpendingLimitAmount.amountInput", [Budget] ’設定したい予算の入力
 driver.Type "id=startDateInput", "[startDate]"                   ’開始日の入力
 collection2.Item(3).Click
 driver.Type "id=endDateInput", "[endDate]"                    ’終了日の入力
 
 driver.Click "id=submitBudget"

 End Sub
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?