【发布时间】:2021-02-04 13:01:18
【问题描述】:
我知道如何打开一个新的并复制所有内容。
而且我还知道如何引用已经打开的 IE 页面。
我正在努力从已经打开的 Internet Explorer 页面复制
请帮忙。
Function GetIE() As Object
'return an object for the open Internet Explorer window, or create new one
For Each GetIE In CreateObject("Shell.Application").Windows() 'Loop to find
If (Not GetIE Is Nothing) And GetIE.Name = "Internet Explorer" Then Exit For 'Found!
Next GetIE
If GetIE Is Nothing Then Set GetIE = CreateObject("InternetExplorer.Application") 'Create
GetIE.Visible = True 'Make IE window visible
' (this is where the code fail) down
IE.ExecWB 17, 0 '// SelectAll
IE.ExecWB 12, 2 '// Copy selection
ActiveSheet.PasteSpecial Format:="Text", link:=False, DisplayAsIcon:=False
Range("A1").Select
IE.Quit
End Function
基本上我需要这段代码:使用已经打开的 IE 窗口而不是 URL
Sub Test()
Dim IE As Object
Sheets("Sheet3").Select
Range("A1:A1000") = "" ' erase previous data
Range("A1").Select
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.Navigate "http://www.aarp.org/" ' should work for any URL
Do Until .ReadyState = 4: DoEvents: Loop
End With
IE.ExecWB 17, 0 '// SelectAll
IE.ExecWB 12, 2 '// Copy selection
ActiveSheet.PasteSpecial Format:="Text", link:=False, DisplayAsIcon:=False
Range("A1").Select
IE.Quit
End Sub
【问题讨论】:
-
您遇到错误了吗?问题到底出在哪里?
-
你能做到吗?
-
请详细说明您的问题,该问题已编辑以附加来自@TimWilliams 的答案,根据您的评论,您尚未实施。友情提示:StackOverflow 不是“我们为您编码”的服务提供商。Introduction to VBA 或Mid-Advanced Tutorials 和我的personal favorite
标签: excel vba internet-explorer copy-paste