我想在电子邮件到达Outlook时启动一个URL。我设置了一个规则并让它触发脚本功能。看起来我想调用ShellExecute在浏览器中启动URL,但是当我点击这一行时:

    ShellExecute(0&, "open", URL, vbNullString, vbNullString, _
vbNormalFocus)

该方法未定义。有什么想法吗?

有帮助吗?

解决方案

ShellExecute是windows dll中的一个函数。 您需要在VBA模块中为此添加声明:

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    ByVal hWnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long      

Shell解决方案和ShellExecute之间的区别在于ShellExecute将使用URL的默认系统处理程序来打开链接。这不一定是IE。您的解决方案将始终在IE中打开它。你的相当于将iexplore.exe放入windows中的运行框中。 ShellExecute相当于只将url放在windows中的运行框中。

其他提示

您也可以使用 Followhyperlink VBA在默认浏览器中打开URL。它还可用于打开已注册应用程序的文档,发送电子邮件和浏览文件夹。

或者,使用 Shell ,如下所示:

Sub LaunchURL(Item As Outlook.MailItem)
    Shell ("C:\Program Files\Internet Explorer\IEXPLORE.EXE" & " " & Item.Body)
End Sub

您可以在此处创建批处理文件:

start http://someurl.com/?a=1^&b=2

并配置Outlook规则以启动此批处理文件。在&之前注意^符号。这是&的转义序列。在批处理文件中。另请注意,您需要在Windows操作系统中设置默认浏览器,几乎百分之百的可能性。

Shell ("CMD /C start http://www.spamcop.net"), vbNormalFocus
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top