3

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

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

方法未定义。有任何想法吗?

4

5 回答 5

4

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 的运行框中。

于 2009-03-06T19:40:14.737 回答
2

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

于 2009-03-09T09:49:59.233 回答
1

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

Sub LaunchURL(Item As Outlook.MailItem)
    Shell ("C:\Program Files\Internet Explorer\IEXPLORE.EXE" & " " & Item.Body)
End Sub
于 2009-03-06T15:48:23.500 回答
1

您可以在编写此文件的位置创建批处理文件:

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

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

于 2014-02-07T06:42:37.043 回答
1
Shell ("CMD /C start http://www.spamcop.net"), vbNormalFocus
于 2014-11-13T10:18:47.807 回答