単二電池

パスワードをマクロコードに書いてコマンドボタンをクリックするとYahoo!乗換案内に毎回自動でログインし定期区間を考慮するにチェックを入れ検索する修正マクロコードを教えていただけますでしょうか。
Windows11 Excel2013です。

Dim driver As Selenium.ChromeDriver

Sub btn_click()
Set driver = New Selenium.ChromeDriver
Dim strValue As String
Dim strValueAfter As String
Dim intCnt As Integer
Dim intDataCnt As Integer
Dim intFee As Integer

' Yahoo!乗換案内にログイン
driver.Get "https://login.yahoo.co.jp/config/login"
driver.FindElementById("username").SendKeys "your_username"
driver.FindElementById("btnNext").Click
driver.FindElementById("passwd").SendKeys "your_password"
driver.FindElementById("btnSubmit").Click

' 定期区間を考慮するにチェックを入れる
driver.Get "https://transit.yahoo.co.jp/"
driver.FindElementById("teiki").Click

intDataCnt = Worksheets("交通費精算書").Range("B11").End(xlDown).Row

For intCnt = 11 To intDataCnt
' 各行のリンクに飛ぶ
driver.Get Worksheets("交通費精算書").Cells(intCnt, 8).Value
' HTMLの取得
strValue = driver.FindElementByXPath("//*[@id=""rsltlst""]/li[1]/dl/dd/ul/li[2]").Text
' 円をブランクに置換
strValueAfter = Replace(strValue, "円", "")

' 往復/片道計算
Select Case Cells(intCnt, 4).Text
Case "往復"
intFee = Int(strValueAfter) * 2
Case "片道"
intFee = Int(strValueAfter)
Case Else
End Select

Worksheets("交通費精算書").Cells(intCnt, 5).Value = intFee
Next

driver.Quit
End Sub

上記マクロコードと以下sheetセルに記載する数式より交通費を書き出します。
https://transit.yahoo.co.jp/search/result?&from= …

「交通費自動精算Excelマクロについて」の質問画像
  • 画像を添付する (ファイルサイズ:10MB以内、ファイル形式:JPG/GIF/PNG)
  • 今の自分の気分スタンプを選ぼう!
あと4000文字

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!


おすすめ情報