简体   繁体   English

无法使用VBA在多个选项卡中输入文本

[英]unable to input text in multiple tabs in ie using vba

I am new to VBA !! 我是VBA新手! I am trying to automate a specific process Which is "Copying the customer details from the excel sheet and opening a IE and going to a specific URL and then pasting the information and clicking the Search button and getting into customers records" I have successfully completed the process but it opens in multiple window as I have to do this for many customers, which was not Nice, so I searched online and successfully opened the customer's records page in multiple TABS in the same WINDOW of IE. 我正在尝试自动化一个特定的过程,即“从excel工作表中复制客户详细信息,然后打开IE并转到特定的URL,然后粘贴信息并单击“搜索”按钮并进入客户记录”,我已经成功完成了流程,但是它在多个窗口中打开,因为我必须为许多客户执行此操作,这不是很好,所以我在线搜索并成功在IE的同一窗口中的多个TABS中打开了客户的记录页面。

Now the real problem is I am unable to enter the customer's information in each window separately, it just enters the details in the very "FIRST WINDOW" and searches it 现在真正的问题是我无法在每个窗口中分别输入客户的信息,它只是在“第一窗口”中输入详细信息并进行搜索

Below is the code I used : 以下是我使用的代码:

Set IE = CreateObject("InternetExplorer.application")
IE.Visible = True
IE.Navigate ThisWorkbook.Sheets("Sheet4").Range("Link")
Do
If IE.ReadyState = 4 Then
Exit Do
Else
DoEvents
End If
Loop
On Error Resume Next
IE.document.all("admin_name").Value = ThisWorkbook.Sheets("Sheet4").Range("User")
IE.document.all("admin_pass").Value = ThisWorkbook.Sheets("Sheet4").Range("Pass")
Set ElementCol = IE.document.getElementsByTagName("button")
For Each link In ElementCol
If link.innerHTML = "LOGIN" Then
link.Click
Exit For
End If
Next
Application.Wait (Now + TimeValue("0:00:04")) ' Utill this line the IE opens the URL (and it is password protected)
' From here on the code opens the customer's records page
x = Range("J1").CurrentRegion.Rows.Count
Y = x - 1
For i = 1 To Y
ActiveCell.Offset(1, -1).Select
Dim navi As String
navi = "Sample URL"
IE.Navigate navi, CLng(2048) ' This is code which i used to open webpages in multiple TABS
Application.Wait (Now + TimeValue("0:00:04"))
Dim Firstname As Variant
Firstname  = ActiveCell.Value
IE.document.getelementsbyname("cc_first_six").Item.innertext = Firstname  
ActiveCell.Offset(0, 1).Select
Dim Lastname As Variant
Lastname = ActiveCell.Value
IE.document.getelementsbyname("cc_last_four").Item.innertext = Lastname 
Set ElementCol = IE.document.getElementsByTagName("a")
For Each link In ElementCol
If link.innerHTML = "Show Results" Then
link.Click
End If
Next
Next i

End Sub 结束子

The Code runs fine but it only uses the first TAB and searches for the all the customers, what I want to do is, it should use the second TAB for the First customer in the excel file and Third TAB for the Second customer in the excel file and so on .... (I am able accomplish my need if i use multiple window option but, i want to do it in the same window but multiple TABS) 该代码运行良好,但是它只使用第一个TAB并搜索所有客户,我想做的是,它应该对excel文件中的第一个客户使用第二个TAB,对excel中的第二个客户使用第三个TAB文件等....(如果我使用多个窗口选项,则可以满足我的需要,但是,我想在同一个窗口中同时使用多个TABS)

I did lot of research but i can't find suitable solution for this problem. 我做了很多研究,但找不到适合该问题的解决方案。 But you can use sendkeys for moving from one tab to other tab. 但是您可以使用sendkey从一个选项卡移动到另一选项卡。

SendKeys "^{TAB}", True
Application.Wait (Now() + TimeValue("00:00:10"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM