Hi,
I have an issue, i use excel mostly for importing data but lately i notice that after i have imported the data and all macros have stopped every few minutes excel will lock up and looks like it is refreshing, also when i go to close and save the workbook it takes 2 minutes or more to close, it may be an issue with my pc but i thought i would check here first, here are the macros i am running.
I have an issue, i use excel mostly for importing data but lately i notice that after i have imported the data and all macros have stopped every few minutes excel will lock up and looks like it is refreshing, also when i go to close and save the workbook it takes 2 minutes or more to close, it may be an issue with my pc but i thought i would check here first, here are the macros i am running.
Code:
Public Function ExecuteWebRequest(url As String) As String
Dim oXHTTP As Object
Set oXHTTP = CreateObject("MSXML2.XMLHTTP")
oXHTTP.Open "GET", url, False
oXHTTP.send
ExecuteWebRequest = oXHTTP.responseText
Set oXHTTP = Nothing
End Function
Code:
Public Function outputtext(text As String)
Dim MyFile As String, fnum As String
MyFile = ThisWorkbook.Path & "\temp.txt"
fnum = FreeFile()
Open MyFile For Output As fnum
Print #fnum, text
Close #fnum
End Function
Code:
Function GetAddress(HyperlinkCell As Range)
GetAddress = Replace _
(HyperlinkCell.Hyperlinks(1).Address, "mailto:", "")
End Function
Code:
Sub clear()
Sheets("Selections").Select
Range("A5:I20000").Select
Selection.ClearContents
Range("G2").Value = 0
End Sub
Code:
Sub Start()
Application.ScreenUpdating = False
If Sheets("Selections").Range("G2").Value <> 0 And Sheets("Selections").Range("G2").Value = Sheets("Selections").Range("G3").Value Then End
Sheets("Selections").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Resize(1, 1).Value _
= Sheets("Selections").Range("D3").Value
Sheets("Meetings").Select
Range("A1:P500").Select
Selection.ClearContents
Meetings
End Sub
Code:
Sub Meetings()
Dim objWeb As QueryTable
Set objWeb = ActiveSheet.QueryTables.Add(Connection:="URL;https://tatts.com/racing/" _
& Format(Sheets("Selections").Range("D3").Value, "DD/MM/YYYY") & "/RaceDay", _
Destination:=Range("$A$1"))
With objWeb
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "2"
.SaveData = True
.Refresh BackgroundQuery:=False
End With
Sheets("Selections").Select
Range("H1:H2").Select
Selection.ClearContents
Range("A2").Select
ActiveCell.FormulaR1C1 = "=Meetings!R[-1]C[27]"
Application.ScreenUpdating = True
newvenue
End Sub
Code:
Sub newvenue()
Sheets("Selections").Range("B2").Value = 1
Range("A2").Select
Set s = ActiveCell
Set h1 = Range("H1")
Set h2 = Range("H2")
h1.Formula = s.Formula
h1.Copy h2
s.Formula = h2.Formula
If Sheets("Selections").Range("A2").Value = "" Then
newvenue
End If
If Sheets("Selections").Range("A2").Value = "END" Then
Sheets("Selections").Range("G2").Value = Sheets("Selections").Range("G2").Value + 1
Start
End If
Import
End Sub
Code:
Sub Import()
Application.ScreenUpdating = False
Sheets("Selections").Select
If Range("B2").Value = Range("G1").Value + 1 Then
GoTo Clr
Else
If Range("B2").Value < 1 Then
GoTo xit
Else
End If
Sheets("Race").Select
Sheets("Race").Cells.Select
Selection.ClearContents
formhtml = ExecuteWebRequest(ThisWorkbook.Sheets("Meetings").Range("V1").Value)
outputtext (formhtml)
Set temp_qt = ThisWorkbook.Sheets("Race").QueryTables.Add(Connection:= _
"URL;" & ThisWorkbook.Path & "\temp.txt" _
, Destination:=ThisWorkbook.Sheets("Race").Range("$A$1"))
With temp_qt
.RefreshStyle = xlOverwriteCells
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "13,17"
.SaveData = True
.Refresh BackgroundQuery:=False
End With
If Sheets("Race").Range("C1").Value = "" Then
Sheets("Race").Cells.Select
Selection.ClearContents
formhtml = ExecuteWebRequest(ThisWorkbook.Sheets("Meetings").Range("V1").Value)
outputtext (formhtml)
Set temp_qt = ThisWorkbook.Sheets("Race").QueryTables.Add(Connection:= _
"URL;" & ThisWorkbook.Path & "\temp.txt" _
, Destination:=ThisWorkbook.Sheets("Race").Range("$A$1"))
With temp_qt
.RefreshStyle = xlOverwriteCells
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "11,12"
.SaveData = True
.Refresh BackgroundQuery:=False
End With
End If
formhtml = ExecuteWebRequest(ThisWorkbook.Sheets("Meetings").Range("V1").Value)
outputtext (formhtml)
Set temp_qt = ThisWorkbook.Sheets("Race").QueryTables.Add(Connection:= _
"URL;" & ThisWorkbook.Path & "\temp.txt" _
, Destination:=ThisWorkbook.Sheets("Race").Range("$A$40"))
With temp_qt
.RefreshStyle = xlOverwriteCells
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "4"
.SaveData = True
.Refresh BackgroundQuery:=False
End With
ActiveSheet.QueryTables.Item(1).Delete
Set temp_qt = Nothing
Kill ThisWorkbook.Path & "\temp.txt"
If ThisWorkbook.Connections.Count > 0 Then ThisWorkbook.Connections.Item(ThisWorkbook.Connections.Count).Delete
End If
Sheets("Meetings").Select
Range("V2").Select
Selection.ClearContents
Sheets("Data").Select
If Range("C1") = "" Then
GoTo xit
Else
Sheets("Selections").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Resize(1, 7).Value = Sheets("Data").Range("A1:G1").Value
End If
xit:
Sheets("Selections").Select
Application.ScreenUpdating = True
Range("B2").Value = Range("B2").Value + 1
Import
Clr: For i = 1 To ActiveWorkbook.Connections.Count
If ActiveWorkbook.Connections.Count = 0 Then Exit Sub
ActiveWorkbook.Connections.Item(i).Delete
i = i - 1
Next i
Sheets("Selections").Select
Range("A2").Select
newvenue
End Sub
Code:
Sub Import2()
ActiveCell.Select
Selection.Copy
Range("V2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.ScreenUpdating = False
Sheets("Race").Select
Sheets("Race").Cells.Select
Selection.ClearContents
formhtml = ExecuteWebRequest(ThisWorkbook.Sheets("Meetings").Range("V1").Value)
outputtext (formhtml)
Set temp_qt = ThisWorkbook.Sheets("Race").QueryTables.Add(Connection:= _
"URL;" & ThisWorkbook.Path & "\temp.txt" _
, Destination:=ThisWorkbook.Sheets("Race").Range("$A$1"))
With temp_qt
.RefreshStyle = xlOverwriteCells
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "13,17"
.SaveData = True
.Refresh BackgroundQuery:=False
End With
If Sheets("Race").Range("C1").Value = "" Then
Sheets("Race").Cells.Select
Selection.ClearContents
formhtml = ExecuteWebRequest(ThisWorkbook.Sheets("Meetings").Range("V1").Value)
outputtext (formhtml)
Set temp_qt = ThisWorkbook.Sheets("Race").QueryTables.Add(Connection:= _
"URL;" & ThisWorkbook.Path & "\temp.txt" _
, Destination:=ThisWorkbook.Sheets("Race").Range("$A$1"))
With temp_qt
.RefreshStyle = xlOverwriteCells
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "11,12"
.SaveData = True
.Refresh BackgroundQuery:=False
End With
End If
formhtml = ExecuteWebRequest(ThisWorkbook.Sheets("Meetings").Range("V1").Value)
outputtext (formhtml)
Set temp_qt = ThisWorkbook.Sheets("Race").QueryTables.Add(Connection:= _
"URL;" & ThisWorkbook.Path & "\temp.txt" _
, Destination:=ThisWorkbook.Sheets("Race").Range("$A$40"))
With temp_qt
.RefreshStyle = xlOverwriteCells
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "4"
.SaveData = True
.Refresh BackgroundQuery:=False
End With
ActiveSheet.QueryTables.Item(1).Delete
Set temp_qt = Nothing
Kill ThisWorkbook.Path & "\temp.txt"
If ThisWorkbook.Connections.Count > 0 Then ThisWorkbook.Connections.Item(ThisWorkbook.Connections.Count).Delete
Sheets("Data").Select
End Sub