VBA web Query with login page

carterr

New Member
Joined
Mar 7, 2017
Messages
2
Morning guys,

I have looked through this and other forums but no code seems to be working for my website and keeps giving errors i am unsure of.


Simply put i am trying to complete a web query to pull data from a table, this information is behind a login page for both username and password. I get to the point of loading IE and then get an error message "the object invoked has disconnected from it's clients". The website is an internal webpage so i am unable to link it for your inspection but i am 95% sure i have the right form id's


Code:
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
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
More details:

This is what i find when i look for the form ID, the page is a JSP so unsure if this is the cause of the issues?

var temp = document.loginform.username.value;
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top