Need Macro help

WildFire

New Member
Joined
Jun 24, 2008
Messages
3
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
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,675
Messages
5,838,716
Members
430,566
Latest member
ChanchalSingh

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
Top