我使用Excel在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行的正下方,该子行在Range(“B2”)之上的子结尾之前。
答案 0 :(得分:0)
txt=ie.document.parentwindow.clipboardData.GetData("TEXT")
这会得到剪贴板。使用Setdata。
您也可以提供浏览器命令。
对OLE对象执行命令,并使用IOleCommandTarget接口返回命令执行的状态。 (即在基本ie.execwb 5, 0
)
<强>语法强>
object.ExecWB( _
cmdID As OLECMDID, _
cmdexecopt As OLECMDEXECOPT, _
[pvaIn As Variant,] _
[pvaOut As Variant])
<强>参数强>
cmdID Long表示要执行的命令的标识符。有关命令标识符的更多信息,请参阅MSHTML命令标识符。
cmdexecopt
OLECMDEXECOPT值,指定命令选项。
pvaIn 可选的。用于指定命令输入参数的Variant。
pvaOut 可选的。用于指定命令输出参数的Variant。
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.