【问题标题】:How to open webpage in VBS如何在VBS中打开网页
【发布时间】:2015-11-05 01:40:52
【问题描述】:

我的代码是

Set WshShell = CreateObject("WScript.shell")
for i = 0 to 50
WshShell.SendKeys(chr(175))
next
Process.Start("CMD", "/C  start chrome.exe http://www.example.com")

它将音量设置为满,然后打开 chrome 到 example.com。但是当我运行它时,我得到了这个错误:

Cannot use parentheses while calling a Sub

如何让它提高音量,然后进入网页?

【问题讨论】:

  • VB.NET VBscript。在标签文本中这么说

标签: vbscript


【解决方案1】:
wshshell.run "www.youtube.com"

【讨论】:

  • 请不要只发布代码作为答案,还要解释您的代码的作用以及它如何解决问题的问题。带有解释的答案通常更有帮助、质量更好,并且更有可能吸引投票
  • 也许没有解释,但在我的测试中,这种方法有效并且具有使用默认浏览器的优势。
【解决方案2】:

这样试试:

Option Explicit
Dim URL,WshShell,i
URL = "www.yahoo.com"
Set WshShell = CreateObject("WScript.shell")
For i = 0 to 50
    WshShell.SendKeys(chr(175))
Next
WshShell.run "CMD /C start chrome.exe " & URL & "",0,False

【讨论】:

    【解决方案3】:

    VBScript 在调用带括号的 sub 时需要 CALL 关键字。您可以像这样编写代码:

    Set WshShell = CreateObject("WScript.shell")
    For i = 0 To 50
        WshShell.SendKeys Chr(175)
    Next
    Process.Start "CMD", "/C  start chrome.exe http://www.example.com"
    

    ...或者像这样:

    Set WshShell = CreateObject("WScript.shell")
    For i = 0 To 50
        Call WshShell.SendKeys(Chr(175))
    Next
    Call Process.Start("CMD", "/C  start chrome.exe http://www.example.com")
    

    注意:调用函数并使用其返回值时不会出现此错误,如下所示:

    Dim strTest
    strTest = SomeFunction()
    

    ...因为在赋值中使用函数时,VBScript 总是需要括号。

    【讨论】:

    • Call Process.Start() 不起作用:/
    【解决方案4】:

    这种方式适合我。

    set wshshell = wscript.CreateObject("wscript.shell")
    wshshell.run "chrome.exe https://stackoverflow.com"
    

    您可以将 chrome.exe 更改为任何浏览器或将网站更改为您想要的任何内容

    【讨论】:

    • 这个答案中是否有其他人没有说的新内容?
    猜你喜欢
    • 2010-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    • 2015-05-11
    相关资源
    最近更新 更多