【发布时间】:2020-12-18 21:33:59
【问题描述】:
我使用 ShellExecute 打开 Outlook 电子邮件中的所有超链接。
我想保存所有打开的网页(我的默认浏览器是 Chrome)。
我试过SendKeys。我怀疑我需要在ShellExecute 和SendKeys 之前放置一些代码,以便它将打开的网页识别为“活动”。换句话说,我想将键盘焦点设置在打开的 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
Sub OpenLinksMessage()
Dim 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 olMail = Application.ActiveExplorer().Selection(1)
Set Reg1 = New RegExp
With Reg1
.Pattern = "(https?[:]//([0-9a-z=\?:/\.&-^!#$%;_])*)"
.Global = True
.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
If InStr(strURL, "unsubscribe") Then GoTo NextURL
If Right(strURL, 1) = ">" Then strURL = Left(strURL, Len(strURL) - 1)
lSuccess = ShellExecute(0, "Open", strURL)
DoEvents
'This is where I think I need codes
SendKeys ("^S"), True
SendKeys ("name"), True
SendKeys "{Enter}", True
NextURL:
Next
End If
Set Reg1 = Nothing
End Sub
弄清楚这一点后,我将调整代码以循环执行以打开并保存100多个链接。
【问题讨论】:
-
我有这段代码使用 IE 对象,但我认为这不是你想要的,对吧?你到底想用 CTRL+S 保存什么?如果您说出目的,我们可以做得更好,然后为您发送密钥...
-
欢迎您的回复。不幸的是,我无法使用 Internet Explorer (IE) - 我试图打开的超链接,仅受 Chrome 支持。澄清一下,我真正需要的是在我打开的 Chrome 网页上设置键盘焦点。
标签: vba google-chrome outlook