我正在构建的宏从 Excel 电子表格中获取名称,打开 Internet Explorer,然后搜索在线目录。搜索目录后,它会拉出一个 Java 表单,其中包含经理的姓名。我可以手动选择经理名称,右键单击,复制快捷方式,然后将其发布回电子表格。但是,我在使用一致的选项卡和复制快捷方式时遇到了问题。
- 有没有一种简单的方法可以让焦点回到 IE 窗口?
- 如何在不手动单击的情况下复制快捷方式?
代码:
Sub Macro1()
'
Dim ie As Object
Set ie = CreateObject("internetexplorer.application")
ie.Visible = True
ie.navigate "****url****"
While ie.busy
DoEvents
Wend
ie.document.getElementById("SSOID").Value = "Z19516732"
ie.document.getElementById("Advanced").Checked = False
ie.document.all("Search").Click
'this loop is to slow the macro as the java form is filled from the search
For i = 1 To 400000000
i = i + 1
Next i
'ie.Object.Activate
ie.document.getElementById("Advanced").Checked = False
ie.document.getElementById("SSOID").Focus
Application.SendKeys "{TAB 6}" ', True
'bring up the control menu/right click
Application.SendKeys "+{F10}"
'copy shortcut is 8 items down on the list
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
Application.SendKeys "{DOWN}"
'enter was not working so the shortcut for the menu is 't'
'SendKeys "{ENTER}"
Application.SendKeys "{t}"
Windows("Book21").Activate
Range("A1").Select
ActiveSheet.Paste
End Sub