2016-07-07 132 views
-1

我想写一个VBA脚本,需要一个电子邮件地址,然后在新窗口中打开它。诀窍是我需要让它在不使用Shell32.dll的情况下运行。VBA - 替代使用Shell32.dll

根据下面的代码,是否有其他方法来重写以下内容?

Option Explicit 

Private Declare Function ShellExecute _ 
    Lib "shell32.dll" Alias "ShellExecuteA" (_ 
    ByVal hWnd As Long, _ 
    ByVal Operation As String, _ 
    ByVal Filename As String, _ 
    Optional ByVal Parameters As String, _ 
    Optional ByVal Directory As String, _ 
    Optional ByVal WindowStyle As Long = vbMinimizedFocus _ 
) As Long 

Public Sub OpenUrl() 

Dim olItem As Outlook.MailItem 
Set olItem = Application.ActiveExplorer().Selection(1) 
Dim sTemp As String 
Dim sURL As String 

If olItem.SenderEmailType = "EX" Then 
    sTemp = olItem.Sender.GetExchangeUser().PrimarySmtpAddress 
Else 
    sTemp = olItem.SenderEmailAddress 
End If 

sURL = "https://afakeurl.com/" + sTemp 

Dim lSuccess As Long 


lSuccess = ShellExecute(0, "Open", sURL) 

End Sub 
+0

使用VB的Shell函数......这基本上是一个Win32 API函数的包装。 –

回答

1

为什么你不想使用它?你能解释一下吗? 您可以使用VBA壳牌:

Shell "cmd.exe" 

一种替代方法是使用

set wsh = CreateObject("WScript.Shell") 
wsh.run "Your thing" 

它使用Microsoft脚本运行。 但我认为在幕后它将使用Shell32.dll无论如何

+0

我们的代码审查团队不希望脚本使用ShellExecute打开链接,但我不确定这是否可能。我只是VBA的新手 – jsaranovic

+0

嗯,我给你写了另一种方法,而不直接使用WINAPI – Mono