Greetings,
I've been reading this forum for a couple years now, but this is my first time posting a question. As they say on the radio call-in shows, "First-time, Long-time."
While I've grown leaps and bounds in my general excel macro writing, I am just beginning to delve into automating Internet Explorer through excel vba. I've spent many hours now trying to find the exact solution to what I'm trying to do, and I've hit a bit of a wall (perhaps I'm just not searching for the right question).
Windows version: Windows 7
Excel version: Excel 2013
Problem: I am attempting to download a file from a webpage using excel vba. The file is generated by clicking on a link which I believe runs some java script. I've figured out how to navigate to the page, and click the link. However at this point, it pops up a "Save Or Open file" box at the bottom of the page and I couldn't quite figure out how to get around this. i've seen multiple suggestions and code snippets, however none of them worked unless there was a direct URL link to the file.
Code:
The HTML for the link itself is:
It's entirely possible I'm missing a simple solution here as my understanding of HTML, java, and general web-based stuff is very very basic. Any code examples or even a nudge in the right direction so I can figure it out myself would be greatly appreciated.
Thanks in advance for any assistance, and let me know if more information or clarification is required.
JL
I've been reading this forum for a couple years now, but this is my first time posting a question. As they say on the radio call-in shows, "First-time, Long-time."
While I've grown leaps and bounds in my general excel macro writing, I am just beginning to delve into automating Internet Explorer through excel vba. I've spent many hours now trying to find the exact solution to what I'm trying to do, and I've hit a bit of a wall (perhaps I'm just not searching for the right question).
Windows version: Windows 7
Excel version: Excel 2013
Problem: I am attempting to download a file from a webpage using excel vba. The file is generated by clicking on a link which I believe runs some java script. I've figured out how to navigate to the page, and click the link. However at this point, it pops up a "Save Or Open file" box at the bottom of the page and I couldn't quite figure out how to get around this. i've seen multiple suggestions and code snippets, however none of them worked unless there was a direct URL link to the file.
Code:
Code:
Sub GetDat()
Dim IE As InternetExplorer
Dim link As Object
Dim LinkCount As Integer
Dim state As Integer
Set IE = New InternetExplorer
IE.Visible = True
IE.Navigate "http://www.fangraphs.com/leaders.aspx?pos=all&stats=bat&lg=all&qual=y&type=1&season=2013&month=13&season1=2013&ind=0&team=0&rost=0&age=0&filter=&players=0#custom"
LinkCount = 0
state = 0
Do Until state = 4
DoEvents
state = IE.ReadyState
Loop
For Each link In IE.Document.Links
If link.innertext = "Export Data" Then
IE.Document.Links(LinkCount).Click
Exit For
End If
LinkCount = LinkCount + 1
Next link
End Sub
The HTML for the link itself is:
HTML:
<a id="LeaderBoard1_cmdCSV" href="javascript:__doPostBack('LeaderBoard1$cmdCSV','')">Export Data</a>
It's entirely possible I'm missing a simple solution here as my understanding of HTML, java, and general web-based stuff is very very basic. Any code examples or even a nudge in the right direction so I can figure it out myself would be greatly appreciated.
Thanks in advance for any assistance, and let me know if more information or clarification is required.
JL