Vba 从Internet Explorer复制所选信息

Vba 从Internet Explorer复制所选信息,vba,excel,internet-explorer,copy-paste,Vba,Excel,Internet Explorer,Copy Paste,我已经使用在Excel中创建了一个基于IE的VBA脚本。VBA脚本打开IE,导航到网站,登录到该网站,输入搜索条件并打开一个新窗口。我使用函数GetIE将新的windows网站镜像回IE的原始实例,这样VBA脚本就可以专注于原始实例。然后单击该窗口上的链接,然后突出显示一些定价信息。但这就是我被困的地方。我迫切需要的代码,将简单地复制我突出显示到我的剪贴板。以下是张贴的代码: Sub ExtractPMDPricing() Dim core As ICore Set core = New Op

我已经使用在Excel中创建了一个基于IE的VBA脚本。VBA脚本打开IE,导航到网站,登录到该网站,输入搜索条件并打开一个新窗口。我使用函数GetIE将新的windows网站镜像回IE的原始实例,这样VBA脚本就可以专注于原始实例。然后单击该窗口上的链接,然后突出显示一些定价信息。但这就是我被困的地方。我迫切需要的代码,将简单地复制我突出显示到我的剪贴板。以下是张贴的代码:

Sub ExtractPMDPricing()

Dim core As ICore
Set core = New OpenTwebstLib.core
Dim IE As InternetExlorer
Set IE = CreateObject("Internet Explorer")
Dim browser As IBrowser


Set browser = core.StartBrowser("xxxxxxxxxxxxxxxx")

Range("A1").Select
Selection.Copy

Call browser.FindElement("div", "id=footer-position-placeholder").Click
Call browser.FindElement("a", "uiname=log in, index=1").Click
Call browser.FindElement("input text", "id=erznr").InputText(ActiveCell.Value)
Call browser.FindElement("td", "index=2").Click
Call browser.FindElement("input button", "id=sub").Click
Application.Wait (Now + #12:00:06 AM#)

Call GetIE

Call browser.FindElement("span", "id=selectionctrl_MATCONTSMALLCTRL_navigatorctrl_treeselectionctrl_MATCONTSMALLCTRL_navigatorctrl_Prices-cnt-start").Click
Call browser.FindElement("input text", "id=selectionctrl_MATCONTSMALLCTRL_subcatviewerctrl_selectionctrl_mod_ergebnis_ga[1].kbetr").RightClick
txt = IE.document.parentWindow.clipboardData.GetData("TEXT")
Range("B2").Select
ActiveCell.PasteSpecial
End Sub

' ZVI:2011-05-30 VBA Macro For Already Open IE Window
' Reference required: Tools - References - Microsoft Internet Controls
Function GetIE()

Dim shellWins As ShellWindows
Dim IE As InternetExplorer

Set shellWins = New ShellWindows

If shellWins.Count > 0 Then
' Get IE
Set IE = shellWins.Item(0)
Else
' Create IE
Set IE = New InternetExplorer
IE.Visible = False
End If

IE.Navigate "xxxxxxxxxxxxxxxx"

Set IE = Nothing
Set shellWins = Nothing

End Function
我需要的复制代码应该正好位于上一次调用browser.findelement行的正下方,位于B2子范围结束之前

txt=ie.document.parentwindow.clipboardData.GetData("TEXT")
这是剪贴板。使用Setdata

您还可以提供浏览器命令

在OLE对象上执行命令,并使用IOleCommandTarget接口返回命令执行的状态。基本ie.execwb 5中的ie,0

语法

参数

cmdID Long,表示要执行的命令的标识符。有关命令标识符的详细信息,请参见MSHTML命令标识符

cmdexecopt

指定命令选项的OLECMDEXECOPT值

pvaIn 可选择的用于指定命令输入参数的变量

IDM_COPY Command ID

--------------------------------------------------------------------------------

Copies the current selection to the clipboard.

C++ Information

Command group CGID_MSHTML (defined in mshtmhst.h)  
Symbolic constant IDM_COPY  
User interface None. Set nCmdExecOpt to OLECMDEXECOPT_DONTPROMPTUSER. 
IOleCommandTarget::Exec parameters pvaIn Set to NULL. 
pvaOut Set to NULL. 

Header file mshtmcid.h  
Applies to IHTMLDocument2::execCommand, IHTMLDocument2::queryCommandEnabled, IHTMLDocument2::queryCommandIndeterm, IHTMLDocument2::queryCommandState, IHTMLDocument2::queryCommandSupported, IHTMLDocument2::queryCommandValue, IOleCommandTarget::Exec, IOleCommandTarget::QueryStatus.  

Minimum Availability

Internet Explorer 4.0 and later. 
pvaOut 可选择的用于指定命令输出参数的变量

IDM_COPY Command ID

--------------------------------------------------------------------------------

Copies the current selection to the clipboard.

C++ Information

Command group CGID_MSHTML (defined in mshtmhst.h)  
Symbolic constant IDM_COPY  
User interface None. Set nCmdExecOpt to OLECMDEXECOPT_DONTPROMPTUSER. 
IOleCommandTarget::Exec parameters pvaIn Set to NULL. 
pvaOut Set to NULL. 

Header file mshtmcid.h  
Applies to IHTMLDocument2::execCommand, IHTMLDocument2::queryCommandEnabled, IHTMLDocument2::queryCommandIndeterm, IHTMLDocument2::queryCommandState, IHTMLDocument2::queryCommandSupported, IHTMLDocument2::queryCommandValue, IOleCommandTarget::Exec, IOleCommandTarget::QueryStatus.  

Minimum Availability

Internet Explorer 4.0 and later. 

PS程序员不允许使用剪贴板,只能使用用户。你应该直接把它放在另一个节目里。谢谢你的回复@面条!我在非基于网络的宏方面有很多经验,所以这对我来说真的是一件好事。我通常有某种类型的脚本记录器,可以根据需要添加的任何代码来编写脚本,所以我一直在脱离网站的纯引用。它现在几乎开始工作了…我能感觉到。但是,当我现在运行宏时,它引用了您提供的代码的顶行,并给出了经典的运行时错误424-需要对象的错误代码。我也在玩浏览器命令,非常有趣。如果有更多的帮助,那就太好了,再次感谢!将ie=CreateObjectInternetExplorer.Dim ie设置为InternetExplorer,然后将ie=CreateObjectInternetExplorer设置为txt=ie.document.parentWindow.clipboardData.GetDataclipboard,但它仍然无法工作…我的计算机讨厌我。。有什么建议吗?我刚刚用你的建议更新了原始代码,使其看起来与我的宏中的一样。它仍然无法识别你给我的txt代码。我是不是错过了一些小东西?非常感谢。