0
上午傢伙,VBA Web查詢與登錄+密碼
使用已經回答了有關問題在這裏我仍然無法獲得任何代碼爲我的特定站點工作,遺憾的是因爲它是一個內部網站,我不能共享的實際現場。
該網站是一個.JSP登錄頁面,這可能會造成問題?該宏在IE中打開登錄頁面,但不會將任何用戶數據輸入到字段中或當前提交。
我也得到錯誤信息「調用的對象已斷開從它的客戶端」一旦宏運行。
Microsoft Internet控制處於活動狀態, 窗體2.0是活躍在引用也
我是相當新的VBA來,如果我在IE中缺少什麼明顯的請讓我知道,我已經降低安全設置也。
編輯我有點確定這是用我的表單ID的,但我不明白我哪裏出錯了?
Sub GetTable()
Dim ieApp As InternetExplorer
Dim ieDoc As Object
Dim ieTable As Object
Dim clip As DataObject
'create a new instance of ie
Set ieApp = New InternetExplorer
'you don’t need this, but it’s good for debugging
ieApp.Visible = True
'assume we’re not logged in and just go directly to the login page
ieApp.Navigate "http://dss-gp-mida-002/MidasDS/login.jsp
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
Set ieDoc = ieApp.Document
'fill in the login form – View Source from your browser to get the control names
With ieDoc.forms(0)
.Username.Value = "Carterr"
.Password.Value = "password"
.submit
End With
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
'now that we’re in, go to the page we want
ieApp.Navigate "http://dss-gp-mida-002/MidasDS/homepage.jsp"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
'get the table based on the table’s id
Set ieDoc = ieApp.Document
Set ieTable = ieDoc.all.Item("sampletable")
'copy the tables html to the clipboard and paste to teh sheet
If Not ieTable Is Nothing Then
Set clip = New DataObject
clip.SetText "" & ieTable.outerHTML & ""
clip.PutInClipboard
Sheet1.Select
Sheet1.Range("A1").Select
Sheet1.PasteSpecial "Unicode Text"
End If
'close 'er up
ieApp.Quit
Set ieApp = Nothing
End Sub
頁來源:
<input type="hidden" name="urlwanted" value=""><input type="hidden" name="sourcePageURL" value=""><input type="hidden" name="ssoiid" value="">
<div>
<div class="form-group">
<label for="username">Username</label><input name="username" id="username" type="text" class="form-control" placeholder="Enter Username">
</div>
<div class="form-group">
<label for="password">Password</label><input name="password" id="password" type="password" class="form-control" placeholder="Enter Password">
</div>
<script>
$("#username").keyup(function(event) {
if (event.which == 13) {
$("#loginform").submit();
}
});
$("#password").keyup(function(event) {
if (event.which == 13) {
$("#loginform").submit();
}
});
</script>
<div class="form-group">
<div class="btn-group-vertical-justified">
<button name="login" type="button" value="Log In" class="btn btn-primary" onclick="document.loginform.ssoiid.value="";document.loginform.submit()">Log In</button>
</div>
根據您不得不登錄/運行宏的方式,您可以作爲第一步檢查您是否已登錄。如果不是手動執行此操作,然後運行宏的其餘部分。 – Luuklag
@Luuklag系統將隨時登錄我出去,不保存用戶的登錄信息,只需在網站設立的方式。 –
我曾經有過類似的東西。我讓代碼打開網站,手動登錄,然後運行代碼的其餘部分。只要代碼在運行它留在記錄下來。這樣的事情會工作,如果你只需要ocasionally運行代碼。 – Luuklag