vba - 如何在ShellExecute刚刚打开的网页上“键盘焦点”?
问题描述
我使用 . 打开 Outlook 电子邮件中的所有超链接ShellExecute
。
我想保存所有打开的网页(我的默认浏览器是 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 对象,并做更好的方法来自动化这个过程
但回答你的问题你可以试试
Dim i As Integer
SendKeys ("^S"), True
On Error Resume Next
For i = 1 To 100
VBA.AppActivate ("Save As")
Next i
On Error GoTo 0
SendKeys ("name"), True
SendKeys "{Enter}", True
推荐阅读
- python - 失去健康之间的延迟
- python - 在 Python 中仅使用 matplotlib 实现 R 的 geom_count()
- python - 如何在 TF 图中端到端训练 TensorFlow 模型之前预处理特征
- javascript - TypeError:无法在“节点”上执行“removeChild”:参数 1 不是“节点”类型
- docusignapi - Docusign - 外部应用程序的管理员同意。未能获得管理员同意的 oauth 令牌
- c++ - 向量堆栈对 | 使用 dfs 在树中的最长路径
- ios - 如何将文本输入从字符串转换为浮点数
- c# - 比较 2 个散列字节数组
- dji-sdk - 检测板载 SDK 中的 RTH(返回首页)
- powershell - 用于打印文件的 Powershell 进度条