Moderatori: Anthony47, Flash30005
pertanto se parti da un archivio completo ma magari fermo al primo di giugno e poi usi la procedura per leggere da “lottoscar” e accodare sul tuo archivio solo le righe mancanti non dovresti avere un archivio complessivo completo?
Anthony ha scritto:Quanto alla facilita' di recupero dell'ultima estrazione, lotto-italia.it e archivioestrazionilotto.it sono equivalenti; ma archivioestrazionilotto.it sembra meno peggio dell'altro per recuperare con calma e senza fretta qualche estrazione precedente.
Nelson ha scritto:Se percio' puoi costruirmi la macro, che aggiorni automaticamente, dovrebbe prelevare i dati da : https://www.lotto-italia.it/lotto/estratti-ruote
La 1° colonna ("A"), sara' quella dedicata alla data.
Anthony il 10-08 ha scritto:Tuttavia mi chiedo perche' siamo qui, visto che il 27-07 scrivevo:pertanto se parti da un archivio completo ma magari fermo al primo di giugno e poi usi la procedura per leggere da “lottoscar” e accodare sul tuo archivio solo le righe mancanti non dovresti avere un archivio complessivo completo?
E il codice per fare cio' l'avevo gia' pubblicato il 22-7
#If VBA7 Then
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
#Else
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
#End If
Sub Lottololast()
Dim ZipPath As String, Ret As Variant, mySplit
'
Sheets("ArchivioLS").Select
Range("A1:BE100000").ClearContents
'Scarica file .zip:
'
'>>>> PARTE MODIFICATA:
ZipPath = "C:\prova\" '<<< Una tua directory dove scaricare il file zippato
'
Ret = GetWebFile("http://lottoscar.altervista.org/ArchivioLotto.italia.zip", ZipPath)
If Ret = 0 Then
MsgBox ("Import .zip fallito. Processo abortito")
Else
Debug.Print "GetWebFile=" & Ret
End If
'
'Espandi .zip:
Call FileDeZip(Ret, ZipPath)
mySplit = Split("\ " & Ret, "\", , vbTextCompare)
'Apre archivio on-line:
Workbooks.Open ZipPath & "\" & "ArchivioLotto.italia.csv"
'<<<< Fine parte Modificata
'
'Copia e Scompattazione archivio
Range("A1").CurrentRegion.Copy ThisWorkbook.Sheets("ArchivioLS").Range("A1")
ActiveWorkbook.Close False
Range("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=True, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 4)), TrailingMinusNumbers:=True
'
Call SortByData
'
Call EXP
'
Range("A1").Select
Selection.ColumnWidth = 13
Range("B1").Select
Selection.ColumnWidth = 5
Range("C1:BE1").Select
Selection.ColumnWidth = 3
'Inserisce colonna #estrazione
Columns("B:B").Insert Shift:=xlToRight
Columns("B:F").NumberFormat = "General"
Call FillColB(1)
Range("A1:B1") = Array("Data", "Indice")
'
Call LS_to_Archivio
'
'
'Msg finale
Sheets("Homepage").Select
MsgBox "Aggiornato archivio terminato ! ! !", vbInformation
End Sub
Sub FillColB(dummy)
'Popola colonna B
Dim wArr, BArr() As Integer, I As Long
Dim oMon As Integer, bCnt As Integer
'
wArr = Range(Range("A2"), Range("A2").End(xlDown)).Value
ReDim BArr(1 To UBound(wArr), 1 To 1)
For I = 1 To UBound(wArr)
If Month(wArr(I, 1)) = oMon Then
bCnt = bCnt + 1
Else
bCnt = 1
oMon = Month(wArr(I, 1))
End If
BArr(I, 1) = bCnt
Next I
Range("B2").Resize(UBound(BArr), 1).Value = BArr
End Sub
Function GetWebFile(ByVal myUrl, ByVal myPath As String) As Variant
'byAnthony, ritorna Image Path & name OPPURE 0 se fail
Dim PathNName As String, URL As String
Dim mySplit, Resp As Long
mySplit = Split(myUrl, "/")
PathNName = myPath & mySplit(UBound(mySplit))
Resp = URLDownloadToFile(0, myUrl, PathNName, 0, 0)
If Resp = 0 Then
GetWebFile = PathNName
Exit Function
Else
GetWebFile = 0
End If
End Function
Sub FileDeZip(ByVal fName As Variant, dzPath As Variant)
'Dim ZipFile As String, OutPath As String, ZipPath As String
'
Set sh = CreateObject("Shell.Application")
sh.Namespace(dzPath & "").CopyHere sh.Namespace(fName).Items, 16 '16=Overwrite same name
Set sh = Nothing
End Sub
Sub EXP()
Dim myR, wArr, vInd As Long, cR As String
Dim oArr()
Dim I As Long, myMatch, J As Long, OldD As Date
Dim DeSh As Worksheet
'
myR = Array("BA", "CA", "FI", "GE", "MI", "NA", "PA", "RO", "TO", "VE", "NZ")
Set DeSh = ThisWorkbook.Sheets("ArchivioLS")
'
wArr = Range("A1").CurrentRegion
ReDim oArr(1 To UBound(wArr), 1 To (UBound(myR) + 1) * 5 + 1)
For I = 0 To UBound(myR)
DeSh.Range("B1").Offset(0, I * 5).Resize(1, 5) = myR(I)
Next I
'Elabora solo il delta:
Dim LastD As Date
LastD = Sheets("Archivio").Cells(Rows.Count, 1).End(xlUp).Value
myMatch = Application.Match(CLng(LastD), DeSh.Range("A:A"), False)
If myMatch > (22 * 11) Then myMatch = myMatch - 20 * 11
'For I = 1 To UBound(wArr)
For I = myMatch To UBound(wArr)
If wArr(I, 1) <> OldD Then
vInd = vInd + 1
OldD = wArr(I, 1)
oArr(vInd, 1) = OldD
End If
cR = wArr(I, 2)
myMatch = Application.Match(wArr(I, 2), DeSh.Range("A1").Resize(1, 60), False)
If Not IsError(myMatch) Then
For J = 0 To 4
oArr(vInd, myMatch + J) = wArr(I, 3 + J)
Next J
End If
DoEvents
Next I
Range("A:BG").Clear
DeSh.Range("A2").Resize(vInd, UBound(oArr, 2)).Value = oArr
End Sub
Sub SortByData()
'
Columns("A:G").Select
ActiveWorkbook.Worksheets("ArchivioLS").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("ArchivioLS").Sort.SortFields.Add2 Key:=Range( _
"A1:A100000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("ArchivioLS").Sort
.SetRange Range("A1:G100000")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
End Sub
Sub LS_to_Archivio()
Dim LS As Worksheet, ARCH As Worksheet
Dim LastD As Date, myMatch, lsDown As Long
'
Set LS = Sheets("ArchivioLS")
Set ARCH = Sheets("Archivio")
LastD = Application.WorksheetFunction.Max(ARCH.Range("A:A"))
myMatch = Application.Match(CLng(LastD), LS.Range("A:A"), False)
lsDown = LS.Cells(myMatch, 1).End(xlDown).Row
If lsDown < Rows.Count Then
LS.Range(LS.Cells(myMatch, 1), LS.Cells(lsDown, 1)).Resize(, 58).Copy _
Destination:=ARCH.Cells(Rows.Count, 1).End(xlUp)
MsgBox ("Righe importate: " & (lsDown - myMatch))
Else
MsgBox ("Non ci sono nuove righe da importare")
End If
End Sub
#If VBA7 Then
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
#Else
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
#End If
Sub LottoloItalia()
Dim ZipPath As String, Ret As Variant, mySplit
'
Sheets("ArchivioLS").Select
Range("A1:BE100000").ClearContents
'Scarica file .zip:
'
'>>>> PARTE MODIFICATA:
ZipPath = "C:\prova\" '<<< Una tua directory dove scaricare il file zippato
'
Ret = GetWebFile("https://www.igt.it/STORICO_ESTRAZIONI_LOTTO/storico01-oggi.zip", ZipPath)
If Ret = 0 Then
MsgBox ("Import .zip fallito. Processo abortito")
Else
Debug.Print "GetWebFile=" & Ret
End If
'
'Espandi .zip:
Call FileDeZip(Ret, ZipPath)
mySplit = Split("\ " & Ret, "\", , vbTextCompare)
'Importa storico
Call TxtImporta(ZipPath & "storico01-oggi.txt")
Call SortByData
'
Call EXP(1)
'
Range("A1").Select
Selection.ColumnWidth = 13
Range("B1").Select
Selection.ColumnWidth = 5
Range("C1:BE1").Select
Selection.ColumnWidth = 3
'Inserisce colonna #estrazione
Columns("B:B").Insert Shift:=xlToRight
Columns("B:F").NumberFormat = "General"
Call FillColB(1)
Range("A1:B1") = Array("Data", "Indice")
'
Call LS_to_Archivio(1)
'
'
'Msg finale
Sheets("Homepage").Select
MsgBox "Aggiornato archivio terminato ! ! !", vbInformation
End Sub
Sub FillColB(Dummy)
'Popola colonna B
Dim wArr, BArr() As Integer, I As Long
Dim oMon As Integer, bCnt As Integer
'
wArr = Range(Range("A2"), Range("A2").End(xlDown)).Value
ReDim BArr(1 To UBound(wArr), 1 To 1)
For I = 1 To UBound(wArr)
If Month(wArr(I, 1)) = oMon Then
bCnt = bCnt + 1
Else
bCnt = 1
oMon = Month(wArr(I, 1))
End If
BArr(I, 1) = bCnt
Next I
Range("B2").Resize(UBound(BArr), 1).Value = BArr
End Sub
Function GetWebFile(ByVal myUrl, ByVal myPath As String) As Variant
'byAnthony, ritorna Image Path & name OPPURE 0 se fail
Dim PathNName As String, URL As String
Dim mySplit, Resp As Long
mySplit = Split(myUrl, "/")
PathNName = myPath & mySplit(UBound(mySplit))
Resp = URLDownloadToFile(0, myUrl, PathNName, 0, 0)
If Resp = 0 Then
GetWebFile = PathNName
Exit Function
Else
GetWebFile = 0
End If
End Function
Sub FileDeZip(ByVal fName As Variant, dzPath As Variant)
'Dim ZipFile As String, OutPath As String, ZipPath As String
'
Set sh = CreateObject("Shell.Application")
sh.Namespace(dzPath & "").CopyHere sh.Namespace(fName).Items, 16 '16=Overwrite same name
Set sh = Nothing
End Sub
Sub EXP(ByVal Dummy)
Dim myR, wArr, vInd As Long, cR As String
Dim oArr()
Dim I As Long, myMatch, J As Long, OldD As Date
Dim DeSh As Worksheet
'
myR = Array("BA", "CA", "FI", "GE", "MI", "NA", "PA", "RM", "TO", "VE", "RN")
Set DeSh = ThisWorkbook.Sheets("ArchivioLS")
'
DeSh.Select
wArr = Range("A1").CurrentRegion
ReDim oArr(1 To UBound(wArr), 1 To (UBound(myR) + 1) * 5 + 1)
For I = 0 To UBound(myR)
DeSh.Range("B1").Offset(0, I * 5).Resize(1, 5) = myR(I)
Next I
'Elabora solo il delta:
Dim LastD As Date
LastD = Sheets("Archivio").Cells(Rows.Count, 1).End(xlUp).Value
myMatch = Application.Match(CLng(LastD), DeSh.Range("A:A"), False)
If myMatch > (22 * 11) Then myMatch = myMatch - 20 * 11
'For I = 1 To UBound(wArr)
For I = myMatch To UBound(wArr)
If wArr(I, 1) <> OldD Then
vInd = vInd + 1
OldD = wArr(I, 1)
oArr(vInd, 1) = OldD
End If
cR = wArr(I, 2)
myMatch = Application.Match(wArr(I, 2), DeSh.Range("A1").Resize(1, 60), False)
If Not IsError(myMatch) Then
For J = 0 To 4
oArr(vInd, myMatch + J) = wArr(I, 3 + J)
Next J
End If
DoEvents
Next I
Range("A2:BG100000").Clear
DeSh.Range("A2").Resize(vInd, UBound(oArr, 2)).Value = oArr
End Sub
Sub SortByData()
'
Columns("A:G").Select
ActiveWorkbook.Worksheets("ArchivioLS").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("ArchivioLS").Sort.SortFields.Add2 Key:=Range( _
"A1:A100000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("ArchivioLS").Sort
.SetRange Range("A1:G100000")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
End Sub
Sub LS_to_Archivio(ByVal Dummy)
Dim LS As Worksheet, ARCH As Worksheet
Dim LastD As Date, myMatch, lsDown As Long
'
Set LS = Sheets("ArchivioLS")
Set ARCH = Sheets("Archivio")
LastD = Application.WorksheetFunction.Max(ARCH.Range("A:A"))
myMatch = Application.Match(CLng(LastD), LS.Range("A:A"), False)
lsDown = LS.Cells(myMatch, 1).End(xlDown).Row
If lsDown < Rows.Count Then
LS.Range(LS.Cells(myMatch, 1), LS.Cells(lsDown, 1)).Resize(, 58).Copy _
Destination:=ARCH.Cells(Rows.Count, 1).End(xlUp)
MsgBox ("Righe importate: " & (lsDown - myMatch))
Else
MsgBox ("Non ci sono nuove righe da importare")
End If
End Sub
Sub TxtImporta(ByVal TXTFile As String)
'
Sheets("ArchivioLS").Select
On Error Resume Next
Range("A1").QueryTable.Delete
On Error GoTo 0
'
Range("A:BG").Clear
Range("A1").Select
Application.CutCopyMode = False
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & TXTFile, Destination:=Range("$A$1"))
.Name = "storico01-oggi"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
Torna a Applicazioni Office Windows
Macro modifica date scelta periodo Autore: Ricky0185 |
Forum: Applicazioni Office Windows Risposte: 11 |
Inserire dati filtrati da 2 file ad un terzo file Autore: Ricky0185 |
Forum: Applicazioni Office Windows Risposte: 14 |
Supporto per sviluppo macro VBA Ordinare per data Autore: Carletto Ribolla |
Forum: Applicazioni Office Windows Risposte: 3 |
Eliminare righe diverse dalla prima data del mese Autore: dipdip |
Forum: Applicazioni Office Windows Risposte: 4 |
Visitano il forum: Nessuno e 38 ospiti