【问题标题】:Open multiple URLs in the Chrome browser在 Chrome 浏览器中打开多个 URL
【发布时间】:2020-03-05 23:30:50
【问题描述】:

我想通过在 Google Chrome 浏览器中打开几个网站的选项来设置我的宏。

我发现的建议来自这些链接:

Parse webpage through VBA with Chromehttps://www.reddit.com/r/excel/comments/48yikv/using_vba_to_launch_chrome_and_log_in/

我也在这里找到了一些解决方案:

https://www.devhut.net/2018/02/01/vba-open-a-url-in-firefox-chrome/

但它主要是指在少数浏览器之间选择选项,这是我不想要的。

到目前为止,我的代码如下所示:

 Sub Websites()
 Dim Chrome As Object
 Dim url1, url2, url3, url4, url5 As String
 Dim postcode1, postcode2, postcode3 As String

 postcode1 = Sheets("Frontsheet").Range("AA2").Value
 postcode2 = Sheets("Frontsheet").Range("AA3").Value

 Dim Location

 url1 = "https://www.google.com/maps/place/+" & postcode1 & "+" & postcode2
 url2 = "https://www.openreach.co.uk/ormaps/pia/v2/"
 url3 = "https://historicengland.org.uk/listing/the-list/map-search?postcode=" & postcode1
 url4 = "https://www.nhs.uk/service-search/other-services/UrgentCare/UrgentCareFinder? 
Location.Id=0&Location.Name=" & postcode1
 url5 = "https://www.mapping.cityoflondon.gov.uk/geocortex/mapping/?viewer=compass&runworkflowbyid=Switch_layer_themes&LayerTheme=Show%20the%20Explore%20The%20City%20layers"

 Set Chrome = "C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe -url"

 With Chrome
    .Visible = True
    .Navigate url1
    .Navigate url2, CLng(2048)
    .Navigate url3, CLng(2048)
    .Navigate url4, CLng(2048)
    .Navigate url5, CLng(2048)
    .Top = 5
    .Left = 5
    .Height = 1300
    .Width = 1900

  End Sub

不幸的是,我收到错误:

类型不匹配

指的是下面这行代码:

   Set Chrome = "C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe -url"

即使我删除了-url 语句,它也会出现。

我也试过这样的:

 Set Chrome = "C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe" & URL

但现在错误状态相当:

变量未定义

因为我设置了变量 url1-url4

那我该如何解析所有这些呢?

【问题讨论】:

  • 你看到蒂姆威廉的comment了吗?
  • Setting 一个字符串到一个对象..?
  • Chrome标签不是对象吗?
  • @Bigben 真的没有其他方法吗?看来这个插件有不少错误。

标签: excel vba


【解决方案1】:

正如 BigBen 通过链接指出的那样,Chrome 不能以与 I.E. 相同的方式用于对象意义。能够。但是您可以像这样请求它打开 URL:

Sub Test

 Dim postcode1 as String, postcode2 As String
 Dim url1 As String, url2 As String, url3 As String, url4 As String, url5 As String

 postcode1 = Sheets("Frontsheet").Range("AA2").Value
 postcode2 = Sheets("Frontsheet").Range("AA3").Value

 url1 = "https://www.google.com/maps/place/+" & postcode1 & "+" & postcode2
 url2 = "https://www.openreach.co.uk/ormaps/pia/v2/"
 url3 = "https://historicengland.org.uk/listing/the-list/map-search?postcode=" & postcode1
 url4 = "https://www.nhs.uk/service-search/other-services/UrgentCare/UrgentCareFinder?Location.Id=0&Location.Name=" & postcode1
 url5 = "https://www.mapping.cityoflondon.gov.uk/geocortex/mapping/?viewer=compass&runworkflowbyid=Switch_layer_themes&LayerTheme=Show%20the%20Explore%20The%20City%20layers"

 OpenChrome url1
 OpenChrome url2
 OpenChrome url3
 OpenChrome url4
 OpenChrome url5

End Sub

Sub OpenChrome(url As String)
    Dim chrome As String
    chrome = "C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe -url"
    Shell (chrome & " " & url)
End Sub

PS。您需要Dim 每种类型,例如String 等。您不能将它们全部列出然后定义类型。

【讨论】:

    猜你喜欢
    • 2014-08-06
    • 1970-01-01
    • 2015-05-29
    • 2017-02-24
    • 2020-05-09
    • 1970-01-01
    • 2013-12-26
    • 2014-12-29
    • 2014-04-22
    相关资源
    最近更新 更多