簡體   English   中英

Excel VBA - 自動填充表單

[英]Excel VBA - auto-populate a form

我有一個小宏使用 shell 命令將我帶到 Chrome 上的網站,但我希望將它鏈接到另一個填充網站上的用戶名和密碼的網站。 這可能嗎? 到目前為止我的代碼:

Sub Logintest2()

  Dim chromePath As String

  chromePath = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"""

  Shell (chromePath & " -url http://www.google.com")

End Sub

我在 Reddit 上發現了一個帖子,說使用 Internet Explorer 會容易得多,因為 Excel/VBA 有一些內置的互操作。 但是,如果您像我一樣討厭 IE。

同一個 Reddit 帖子建議使用名為Selenium Basic 的第三方插件。 我使用此答案下載並安裝它。

以下代碼在Chrome中成功打開谷歌並將搜索框的文字設置為“This is a test”。

Sub Test()
    Dim bot As New WebDriver
    
    bot.Start "chrome", "https://www.google.com"
    bot.Get "/"
    
    bot.FindElementByName("q").SendKeys "This is a test"
    Stop

End Sub

我使用 DevTools (F12) 瀏覽網頁內容,發現搜索框有name="q"

祝你好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM