StevenIramus
New Member
- Joined
- Sep 2, 2014
- Messages
- 3
I am using excel and VBA to download a number of web pages and parse data from those webpages. I have my code set up but on occasion (every several hundred pages) the application crashes because it can't get a response from the internet.
My question is can I add code that essentially instructs Excel to wait ~5 seconds for a page to load. If the page doesn't load cancel and retry? Here is my code:
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 8/30/2014 by [Redacted]
'
Dim StrPath As String
StrPath = "[Redacted]"
Application.ScreenUpdating = False
y = ThisWorkbook.Sheets("Performance").Range("A45").Value + 1
For x = y To 2008000000
Workbooks.Open (StrPath & x)
Workbooks("Performance.asp").Worksheets("Performance").Range("A1:AS22").Copy
ThisWorkbook.Sheets("Performance").Range("A1:AS22").PasteSpecial
Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ThisWorkbook.Sheets("Performance").Range("A45").Value = x
If ThisWorkbook.Sheets("Performance").Range("B42").Value = "1" Then
ThisWorkbook.Sheets("Position").Rows("3:3").Insert Shift:=xlDown
If ThisWorkbook.Sheets("Performance").Range("B42").Value = "1" Then
ThisWorkbook.Sheets("Performance").Range("A67:EQ67").Copy
If ThisWorkbook.Sheets("Performance").Range("B42").Value = "1" Then
ThisWorkbook.Worksheets("Position").Range("A3:EQ3").PasteSpecial
Paste:=xlPasteValues
If ThisWorkbook.Sheets("Performance").Range("B42").Value = "2" Then
ThisWorkbook.Sheets("Pitch").Rows("3:3").Insert Shift:=xlDown
If ThisWorkbook.Sheets("Performance").Range("B42").Value = "2" Then
ThisWorkbook.Sheets("Performance").Range("A70:FF70").Copy
If ThisWorkbook.Sheets("Performance").Range("B42").Value = "2" Then
ThisWorkbook.Worksheets("Pitch").Range("A3:FF3").PasteSpecial
Paste:=xlPasteValues
Application.CutCopyMode = False
Workbooks("Performance.asp").Close SaveChanges:=False
ThisWorkbook.Sheets("Performance").Range("A1:AS22").ClearContents
If Int(x / 100) = x / 100 Then ThisWorkbook.Save
Next x
Application.ScreenUpdating = True
End Sub
My question is can I add code that essentially instructs Excel to wait ~5 seconds for a page to load. If the page doesn't load cancel and retry? Here is my code:
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 8/30/2014 by [Redacted]
'
Dim StrPath As String
StrPath = "[Redacted]"
Application.ScreenUpdating = False
y = ThisWorkbook.Sheets("Performance").Range("A45").Value + 1
For x = y To 2008000000
Workbooks.Open (StrPath & x)
Workbooks("Performance.asp").Worksheets("Performance").Range("A1:AS22").Copy
ThisWorkbook.Sheets("Performance").Range("A1:AS22").PasteSpecial
Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ThisWorkbook.Sheets("Performance").Range("A45").Value = x
If ThisWorkbook.Sheets("Performance").Range("B42").Value = "1" Then
ThisWorkbook.Sheets("Position").Rows("3:3").Insert Shift:=xlDown
If ThisWorkbook.Sheets("Performance").Range("B42").Value = "1" Then
ThisWorkbook.Sheets("Performance").Range("A67:EQ67").Copy
If ThisWorkbook.Sheets("Performance").Range("B42").Value = "1" Then
ThisWorkbook.Worksheets("Position").Range("A3:EQ3").PasteSpecial
Paste:=xlPasteValues
If ThisWorkbook.Sheets("Performance").Range("B42").Value = "2" Then
ThisWorkbook.Sheets("Pitch").Rows("3:3").Insert Shift:=xlDown
If ThisWorkbook.Sheets("Performance").Range("B42").Value = "2" Then
ThisWorkbook.Sheets("Performance").Range("A70:FF70").Copy
If ThisWorkbook.Sheets("Performance").Range("B42").Value = "2" Then
ThisWorkbook.Worksheets("Pitch").Range("A3:FF3").PasteSpecial
Paste:=xlPasteValues
Application.CutCopyMode = False
Workbooks("Performance.asp").Close SaveChanges:=False
ThisWorkbook.Sheets("Performance").Range("A1:AS22").ClearContents
If Int(x / 100) = x / 100 Then ThisWorkbook.Save
Next x
Application.ScreenUpdating = True
End Sub