VBA - 使用Shell32.dll的替代方法

时间:2016-07-07 13:29:18

标签: vba

我试图编写一个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

1 个答案:

答案 0 :(得分:1)

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

Shell "cmd.exe"

另一种方法是使用

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

这使用Microsoft Scripting Runtime。 但我认为它背后会使用Shell32.dll