【发布时间】:2020-07-10 18:48:05
【问题描述】:
所以我使用以下代码从电子邮件中打开超链接。此超链接打开网页并打开下载窗口以选择下载 CSV 的位置和名称(所有这些都在 Chrome 中)。我希望能够选择所述文件的下载位置和名称。非常感谢您的帮助:)
Private Declare PtrSafe 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 OpenLinks(olMail As Outlook.MailItem)
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Dim strURL As String
Dim lSuccess As Long
Set Reg1 = New RegExp
With Reg1
.Pattern = "(https?[:]//([0-9a-z=\?:/\.&-^!#$%;_])*)>"
.Global = False
.IgnoreCase = True
End With
If Reg1.Test(olMail.Body) Then
Set M1 = Reg1.Execute(olMail.Body)
For Each M In M1
strURL = M.SubMatches(0)
Debug.Print strURL
lSuccess = ShellExecute(0, "Open", strURL)
Next
End If
Set Reg1 = Nothing
Set oApp = Nothing
End Sub
我查看了其他网站,但找不到类似的东西。
【问题讨论】:
-
@Namandeep_Kaur 看起来不错,问题是超链接直接在我的chrome浏览器中打开,一旦我尝试使用它,它什么也没做
标签: vba csv google-chrome outlook download