Excel VBA:在锁定屏幕的情况下运行 IE.ExecWB 12,2 返回“方法“ExecWB”;对象“IWebBrowser2”的失败”
只要屏幕未锁定,以下简单代码就可以正常工作。如果在屏幕锁定时运行(Ctrl+Alt+Del、Alt-K),则会返回错误代码 80040100“对象‘IWebBrowser2’的方法‘ExecWB’失败”
- 在简单家用电脑上的 Windows 10、64 位上运行 Excel 2019 /network
- 这个例程已经工作了很多年,没有出现任何问题。
- 问题是在上周左右开始的,并且在两台不同的 Win 10 PC 上都是相同的。更新,另一个由于某种原因无法下载最新的累积更新我不知道
- 我已经尝试使用 InternetExplorerMedium
知道出了什么问题吗?
Sub CopyURLSheet_Slim()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
Sleep (3000) ' user locks screen
On Error GoTo Err_Clear
With IE
.silent = True
.Visible = True
.navigate "https://www.morningstar.com"
While .Busy Or .ReadyState <> 4 ' 4 = READYSTATE_COMPLETE
DoEvents
Wend
WriteLog ("Log3..")
IE.ExecWB 17, 0 'SelectAll
WriteLog ("Log4..")
IE.ExecWB 12, 2 'Copy selection - CAUSES ERROR 0040100 Method 'ExecWB' of object 'IWebBrowser2' failed
Sheets("Sheet1").Select
Range("MS_url").Select
WriteLog ("Log7..")
Sheets("Sheet1").PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
.Quit
End With
Err_Clear:
If Err <> 0 Then
WriteLog ("Error: " & Hex(Err.Number) & " " & Err.Description)
Err.Clear
Resume Next
End If
Err:
Set IE = Nothing
On Error GoTo 0
End Sub
Output
Log3
Log4
Error: 80040100 Method 'ExecWB' of object 'IWebBrowser2' failed
Log7
The following simple code works fine as long as the screen isn’t locked. If it is run when the screen is locked (Ctrl+Alt+Del, Alt-K) then it returns error code 80040100 “Method 'ExecWB' of object 'IWebBrowser2' failed"
- Running Excel 2019 on Windows 10, 64bit on simple home PCs/network
- This routine has worked for years without problems.
- The problem started in the last week or so and is the same on two different Win 10 PCs. One PC has all latest updates, the other for some reason fails to download the latest cumulative updates. I am not aware of any other changes that have been made.
- I have tried using InternetExplorerMedium
Any idea what has gone wrong?
Sub CopyURLSheet_Slim()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
Sleep (3000) ' user locks screen
On Error GoTo Err_Clear
With IE
.silent = True
.Visible = True
.navigate "https://www.morningstar.com"
While .Busy Or .ReadyState <> 4 ' 4 = READYSTATE_COMPLETE
DoEvents
Wend
WriteLog ("Log3..")
IE.ExecWB 17, 0 'SelectAll
WriteLog ("Log4..")
IE.ExecWB 12, 2 'Copy selection - CAUSES ERROR 0040100 Method 'ExecWB' of object 'IWebBrowser2' failed
Sheets("Sheet1").Select
Range("MS_url").Select
WriteLog ("Log7..")
Sheets("Sheet1").PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
.Quit
End With
Err_Clear:
If Err <> 0 Then
WriteLog ("Error: " & Hex(Err.Number) & " " & Err.Description)
Err.Clear
Resume Next
End If
Err:
Set IE = Nothing
On Error GoTo 0
End Sub
Output
Log3
Log4
Error: 80040100 Method 'ExecWB' of object 'IWebBrowser2' failed
Log7
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以在 IE.ExecWB 12, 2 之前写 Application.Wait (Now + TimeValue("00:00:05")) ,它对我有用。参考来了来自 这里
You can write Application.Wait (Now + TimeValue("00:00:05")) before IE.ExecWB 12, 2,it works for me.Reference is come from here