2016-12-22 35 views
0

我是新來的VBA!我試圖自動化一個特定的過程,即「複製Excel表格中的客戶詳細信息,打開IE並轉到特定的URL,然後粘貼信息並單擊」搜索「按鈕並進入客戶記錄」我已成功完成但它在多個窗口中打開,因爲我必須爲許多客戶執行此操作,這不是很好,所以我在線搜索並在IE的同一窗口中成功打開了多個TABS中的客戶記錄頁面。無法輸入文本中,即多個標籤使用VBA

現在真正的問題是我無法單獨輸入客戶在每個窗口的信息,它只是進入細節非常「第一窗口」,並搜索其

下面是我使用的代碼:

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 

末次

代碼運行正常,但它僅使用第一個選項卡並搜索所有的客戶,我想要做的是,它應該使用第二個選項卡以客爲先在Excel中文件和第二個第三個選項卡客戶在Excel文件等等......(我能完成我的需要,如果我使用多個窗口的選擇,但我想這樣做在同一個窗口,但多個標籤)

回答

0

我做了很多的研究,但我無法找到適合此問題的解決方案。但是你可以使用sendkeys從一個標籤移動到其他標籤。

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

感謝您的答覆!然而,在正是我應該將上面的代碼線 – David

+0

的SendKeys用於發送鍵盤按下的按鈕等「^ {TAB}」被用於發送對CTRL + TAB鍵組合快捷鍵。你必須檢查哪個組合鍵適合你。我會建議你使用其他方法,而不是使用多個選項卡,因爲我找不到任何合適的解決方案在不同的選項卡之間移動。 –

+0

我使用多個Tabs的原因是因爲在運行代碼後,我手動複製了一些信息並將其粘貼到Excel中! :-( – David