[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2518
  • Last Modified:

Using Internet Explorer Object in VBA

I have been using Shell, AppActivate, and SendKeys in an Excel VBA macro to post form data and download a file in response (did I hear somebody say Ouch?). Needless to say, the macro is inflexible and doesn't handle errors very well. For  example, I post a stock symbol "MSFT" to the URL "http://www.cboe.com/DelayedQuote/QuoteTableDownload.aspx", download the response file "QuoteData.dat", and save the file in a local folder. It seems to me that the Internet Explorer Object might be a solution, but I want to hear from the Experts before I make the attempt. First, is it feasible to perform the above task using the Internet Explorer Object in VBA? Second, if it is feasible, what objects, properties and methods would be involved? And third, am I overlooking a better alternative? A code example would be greatly appreciated.

Thanks
0
mdmat
Asked:
mdmat
1 Solution
 
GrahamSkanCommented:
Set a reference to Microsoft Internet Explorer and Microsoft HTML Library. This is some starter code:

Private Sub Command1_Click()
Dim Ie As New InternetExplorer
Dim objDocument As MSHTML.HTMLDocument
Dim t As Date
Dim i As Integer

Ie.Navigate "http://www.cboe.com/DelayedQuote/QuoteTableDownload.aspx"
Ie.Visible = True

'QnD Timer
t = DateAdd("s", 3, Now)
Do Until Now > t
    DoEvents
Loop

Set objDocument = Ie.Document

Do
    DoEvents
Loop Until objDocument.ReadyState = "complete"
Ie.Document.All.Item("ticker").Value = "MSFT"
'routine to find button
'For i = 0 To Ie.Document.All.length - 1
    'If Ie.Document.All.Item(i).tagName = "INPUT" Then
        'If Ie.Document.All.Item(i).Type = "submit" Then
            'Debug.Print i
        'End If
    'End If
'Next i
Ie.Document.All.Item(400).Click
End Sub


0
 
mdmatAuthor Commented:
GrahamSkan,

Thanks for the starter code and the pointer to the object libraries. I will be working with what you have provided and will probably post more questions when I have things in better focus.

MDMAT
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now