View Full Version : log into an internet site

09-20-2005, 01:33 PM
i recently found an article from brettdj on how to login to a web site and get to the page you wanted to down load.

the code as modified by me (for my benifit)Option Explicit

Sub IE_login()
Dim ie As InternetExplorer
Dim C
Dim ULogin As Boolean, ieForm
Dim MyPass As String, MyLogin As String
Dim newHour As String
Dim newMinute As String
Dim newSecond As String
Dim waitTime As String
MyLogin = Application.InputBox("Please enter your login", "xxxxx username", Default:="repacc", Type:=2)
MyPass = Application.InputBox("Please enter your password", "xxxxx Password", Default:="replog7", Type:=2)

If MyLogin = "" Or MyPass = "" Then GoTo redo

Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "http://www.xxxxx.com/modules/shop/memb_login.asp"
'Loop until ie page is fully loaded
Do Until ie.ReadyState = READYSTATE_COMPLETE
'Look for password Form by finding test "Password"
For Each ieForm In ie.Document.forms
If InStr(ieForm.innertext, "Password") <> 0 Then
ULogin = True
'enter details
ieForm(2).Value = MyLogin
ieForm(3).Value = MyPass
' added next 4 lines to go directly to page to download ie.Navigate "http://www.xxxxx.com/pages/tradedownload.asp"
With ActiveSheet
ie.Navigate "http://www.xxxxx.com/modules/shop/fullpricelist.asp "
End With
Exit For
End If
If ULogin = False Then MsgBox "User is aleady logged in"
Set ie = Nothing
End Sub

Sub SetRefs()
Dim ObRef
On Error Resume Next
' Adds Internet Controls Ref
ThisWorkbook.VBProject.References.AddFromGuid "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 1, 1
End Sub
what i am having difficulties in working out how to downloading the page either to a new workbook or update an existing workbook (html) at present or as an excel file at present this is done manually.
can any one suggest a way forward to resolve this :banghead:

09-20-2008, 07:04 AM
When you login the website successfully,you may use webquery to download the webpage or use ie.document to scratch the data what you want.