如何在电子邮件到达时启动URL

时间:2022-07-18 21:01:46

I would like to launch a URL when an email arrives in Outlook. I setup a rule and have it trigger a script function. It looks like I want to call ShellExecute to launch the URL in a browser, but when I hit this line:

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

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

The method is not defined. Any ideas?

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

5 个解决方案

#1


ShellExecute is a function in a windows dll. You need to add a declaration for it like this in a VBA module:

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      

The difference between your Shell solution and ShellExecute is that ShellExecute will use the default system handler for URLs to open the link. This doesn't have to be IE. Your solution will always open it in IE. Yours is the equivalent of putting iexplore.exe into the run box in windows. ShellExecute is the equivalent of just putting the url in the run box in windows.

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

#2


You can also use Followhyperlink from VBA to open URLs in the default browser. It can also be used to open documents with the registered application, to send emails and to browse folders.

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

#3


Alternatively, use Shell, like this:

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

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

#4


You can create batch file where you write this:

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

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

And you configure Outlook rule to launch this batch file. Notice ^ sign before &. This is escape sequence for & in batch files. Also notice that you need to have default browser set in your Windows OS, almost 100% probability that you have it.

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

#5


Shell ("CMD /C start http://www.spamcop.net"), vbNormalFocus

#1


ShellExecute is a function in a windows dll. You need to add a declaration for it like this in a VBA module:

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      

The difference between your Shell solution and ShellExecute is that ShellExecute will use the default system handler for URLs to open the link. This doesn't have to be IE. Your solution will always open it in IE. Yours is the equivalent of putting iexplore.exe into the run box in windows. ShellExecute is the equivalent of just putting the url in the run box in windows.

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

#2


You can also use Followhyperlink from VBA to open URLs in the default browser. It can also be used to open documents with the registered application, to send emails and to browse folders.

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

#3


Alternatively, use Shell, like this:

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

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

#4


You can create batch file where you write this:

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

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

And you configure Outlook rule to launch this batch file. Notice ^ sign before &. This is escape sequence for & in batch files. Also notice that you need to have default browser set in your Windows OS, almost 100% probability that you have it.

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

#5


Shell ("CMD /C start http://www.spamcop.net"), vbNormalFocus