I'm using the below macro. Does the following
1. Login to yahoo
2. refresh the sheet with url page through web query
First part of loggin in works, however 2nd part doesn't work. I assumed that because i have already logged in it should be able to refresh on the next page but it basically just imports the login page. Some how it doesn't remember what it did few steps back. Any suggestions?
Option Explicit
Public Enum IE_READYSTATE
Uninitialised = 0
Loading = 1
Loaded = 2
Interactive = 3
complete = 4
End Enum
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 6/23/2008 by
'
'
Const cURL = "http://in.groups.yahoo.com/group/bse-nse2005/files/00-STOCKS%20DATA%20FILES/06%20-%20June%202008"
Const cUserID = "XXXX"
Const cPwd = "YYYY"
Dim ie As Object
Dim doc As HTMLDocument
Dim PageForm As HTMLFormElement
Dim UserIdBox As HTMLInputElement
Dim PasswordBox As HTMLInputElement
Dim FormButton As HTMLInputButtonElement
Dim Elem As IHTMLElement
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate cURL
Do While ie.busy Or Not ie.readyState = IE_READYSTATE.complete: DoEvents: Loop
Set doc = ie.document
Debug.Print "Login page: " & ie.LocationURL
For Each Elem In doc.all
Next
Set PageForm = doc.forms(0)
Set UserIdBox = PageForm.elements("UserName")
UserIdBox.Value = cUserID
Set PasswordBox = PageForm.elements("passwd")
PasswordBox.Value = cPwd
PageForm.submit
With Selection.QueryTable
.Connection = _
"URL;http://in.groups.yahoo.com/group/bse-nse2005/files/00-STOCKS%20DATA%20FILES/06%20-%20June%202008"
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingAll
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
1. Login to yahoo
2. refresh the sheet with url page through web query
First part of loggin in works, however 2nd part doesn't work. I assumed that because i have already logged in it should be able to refresh on the next page but it basically just imports the login page. Some how it doesn't remember what it did few steps back. Any suggestions?
Option Explicit
Public Enum IE_READYSTATE
Uninitialised = 0
Loading = 1
Loaded = 2
Interactive = 3
complete = 4
End Enum
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 6/23/2008 by
'
'
Const cURL = "http://in.groups.yahoo.com/group/bse-nse2005/files/00-STOCKS%20DATA%20FILES/06%20-%20June%202008"
Const cUserID = "XXXX"
Const cPwd = "YYYY"
Dim ie As Object
Dim doc As HTMLDocument
Dim PageForm As HTMLFormElement
Dim UserIdBox As HTMLInputElement
Dim PasswordBox As HTMLInputElement
Dim FormButton As HTMLInputButtonElement
Dim Elem As IHTMLElement
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate cURL
Do While ie.busy Or Not ie.readyState = IE_READYSTATE.complete: DoEvents: Loop
Set doc = ie.document
Debug.Print "Login page: " & ie.LocationURL
For Each Elem In doc.all
Next
Set PageForm = doc.forms(0)
Set UserIdBox = PageForm.elements("UserName")
UserIdBox.Value = cUserID
Set PasswordBox = PageForm.elements("passwd")
PasswordBox.Value = cPwd
PageForm.submit
With Selection.QueryTable
.Connection = _
"URL;http://in.groups.yahoo.com/group/bse-nse2005/files/00-STOCKS%20DATA%20FILES/06%20-%20June%202008"
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingAll
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub