我正在编写一个宏来进入 Internet Explorer,搜索和员工编号,从该搜索中找到经理,最后将其复制并粘贴到工作簿中的一个单元格中......但是,它似乎总是落后于“复制”后面。我的意思是,如果我在运行宏之前复制某些内容,然后运行它,复制的内容会进入单元格。然而,我再次点击运行,它会复制经理姓名。它似乎总是落后一个“副本”,或者选择剪贴板上第二个最近的项目。此外,如果我在复制和粘贴代码之前清除剪贴板,我会收到错误消息。这是为什么?
`Sub Macro1()
'
Dim ie As Object
Set ie = CreateObject("internetexplorer.application") 'start up IE
Dim HWNDSrc As Long
HWNDSrc = ie.HWND 'to setup for focusing internet explorer
ie.Visible = True
ie.navigate "http://url.com/" 'address to find
While ie.Busy 'loop until ie is done loading
DoEvents
Wend
Call WaitForIE(ie, HWNDSrc, 7) 'to check and make sure ie is done loading
ie.document.getElementById("SSOID").Value = "m1z016p32" 'input into search box
ie.document.getElementById("SSOID").Select
SetForegroundWindow HWNDSrc 'focuses the active application
Application.SendKeys "~" 'enter key
ie.document.getElementById("Advanced").Checked = False 'make sure the advanced box is unchecked
For i = 1 To 200000000 'loop to load the search
i = i + 1
Next i
ie.document.getElementById("Advanced").Checked = False
ie.document.getElementById("SSOID").Select 'focuses the cursor so the tabs will align
SetForegroundWindow HWNDSrc
Application.SendKeys "{TAB 6}" 'tab to location
Application.SendKeys "+{F10}" 'right click on the manger name
Application.SendKeys "{DOWN}" 'goes down to 'copyshortcut'
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
Application.SendKeys "~" '[presses enter
Windows("Book21").Activate 'workbook o activate
Range("A1").Select 'selects the cell
ActiveSheet.Paste 'past the data
End Sub`