Who is John Galt
New Member
- Joined
- Sep 6, 2010
- Messages
- 4
I am using Excel 2010, Windows XP.
I am interested in downloading from the internet archived excel files and save them to my "C" drive.
The data can be found here (scroll down a little): http://www.pjm.com/markets-and-opera...-time/lmp.aspx
Each file represents a day's worth of price data. I have written the following VBA code that works well enough with ONE BIG GLITCH, the website stops my code, generates a message box saying:
"Some files can contain viruses or otherwise be harmful to your computer ... Would you like to open this file?"
and waits for a response!!!
As a result any automation is stopped dead in its tracks because my code requires me to sit there and press "OK" to the previous question.
My question is ... "What VBA Code can I write to have the macro answer this question enabling me to use a loop download and save a months worth of files while enjoying a cup of coffee?"
I assume the solution is something along the lines of when closing a workbook without saving it ----> ActiveWorkbook.Close savechanges:=False
The code I have written is as follows (it is set up to download & save the 31 files representing the 31 days of August 2010):
<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --></style>
Sub GetDailyData()<o></o>
<o> </o>
Dim WebSiteAddress As String<o></o>
<o> </o>
Dim DayNumber As Variant<o></o>
<o> </o>
DayNumber = Array("01", "02", "03", "04", "05", "06", "07", "08", "09", 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31)<o></o>
<o> </o>
For i = 1 To 31<o></o>
<o> </o>
WebSiteAddress = "http://www.pjm.com/pub/account/lmp/201008" & DayNumber(i) & ".csv"<o></o>
<o></o>
ActiveWorkbook.FollowHyperlink Address:=WebSiteAddress, NewWindow:=True<o></o>
<o></o>
Dim WBO As Workbook ' original workbook<o></o>
Set WBO = ActiveWorkbook<o></o>
fn = "C:\PJM\August" & " " & i & ", 2010" & ".xlsm
<o></o>
WBO.SaveAs Filename:= fn<o></o>
WBO.Close SaveChanges:=False<o></o>
<o></o>
Next i<o></o>
<o></o>
[FONT="]End Sub[/FONT]
Thank you in advance for any assistance that may be provided.
Sincerely,
Who is John Galt
I am interested in downloading from the internet archived excel files and save them to my "C" drive.
The data can be found here (scroll down a little): http://www.pjm.com/markets-and-opera...-time/lmp.aspx
Each file represents a day's worth of price data. I have written the following VBA code that works well enough with ONE BIG GLITCH, the website stops my code, generates a message box saying:
"Some files can contain viruses or otherwise be harmful to your computer ... Would you like to open this file?"
and waits for a response!!!
As a result any automation is stopped dead in its tracks because my code requires me to sit there and press "OK" to the previous question.
My question is ... "What VBA Code can I write to have the macro answer this question enabling me to use a loop download and save a months worth of files while enjoying a cup of coffee?"
I assume the solution is something along the lines of when closing a workbook without saving it ----> ActiveWorkbook.Close savechanges:=False
The code I have written is as follows (it is set up to download & save the 31 files representing the 31 days of August 2010):
<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --></style>
Sub GetDailyData()<o></o>
<o> </o>
Dim WebSiteAddress As String<o></o>
<o> </o>
Dim DayNumber As Variant<o></o>
<o> </o>
DayNumber = Array("01", "02", "03", "04", "05", "06", "07", "08", "09", 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31)<o></o>
<o> </o>
For i = 1 To 31<o></o>
<o> </o>
WebSiteAddress = "http://www.pjm.com/pub/account/lmp/201008" & DayNumber(i) & ".csv"<o></o>
<o></o>
ActiveWorkbook.FollowHyperlink Address:=WebSiteAddress, NewWindow:=True<o></o>
<o></o>
Dim WBO As Workbook ' original workbook<o></o>
Set WBO = ActiveWorkbook<o></o>
fn = "C:\PJM\August" & " " & i & ", 2010" & ".xlsm
<o></o>
WBO.SaveAs Filename:= fn<o></o>
WBO.Close SaveChanges:=False<o></o>
<o></o>
Next i<o></o>
<o></o>
[FONT="]End Sub[/FONT]
Thank you in advance for any assistance that may be provided.
Sincerely,
Who is John Galt