i'm writing a macro to go into internet explorer, search and employee number, find the manager from that search, and finally copy+paste it to a cell in the workbook.... however, it seems to always be one behind "copy" behind. By that i mean, if i copy something before running the macro, then run it, what is copied goes in the cell. Yet, i hit run again, and it copies the manager name. it seems to always be one "copy" behind, or selects the second most recent item on the clipboard. Also if i clear the clipbaord before copying and pasting in the coade, i get an error. Why is that?
`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`