
Sub Macro1()
'
' Macro1 Macro
'
A = "UNI.MI"
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;******/q/hp?s=A&d=11&e=23&f=2009&g=d&a=0&b=1&c=2003&z=66&y=66" _
, Destination:=Range("$A$1"))
.Name = "hp?s=A&d=11&e=23&f=2009&g=d&a=0&b=1&c=2003&z=66&y=66"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "21"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub |
Private Sub CommandButton1_Click() ZZ = "UNIP.MI" A = 66 B = 132 C = 198 D = 264 E = 330 F = 396 G = 462 H = 528 I = 594 L = 660 M = 132 N = 132 O = 132 P = 132 Q = 132 R = 132 S = 132 T = 132 U = 132 V = 132 Z = 132 ZZZ = "A3" AA = "A73" BB = "A146" CC = "A219" With ActiveSheet.QueryTables.Add(Connection:= _ "URL;********/q/hp?s=" & ZZ _ , Destination:=Range(ZZZ)) .Name = "hp?s=" & ZZ .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingNone .WebTables = "21" .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With With ActiveSheet.QueryTables.Add(Connection:= _ "URL;*******/q/hp?s=" & ZZ & "&d=11&e=23&f=2009&g=d&a=0&b=1&c=2003&z=" & A & "&y=" & A _ , Destination:=Range(AA)) .Name = "hp?s=" & ZZ & "&d=11&e=23&f=2009&g=d&a=0&b=1&c=2003&z=" & A & "&y=" & A .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingNone .WebTables = "21" .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End Sub |
‘query originale
With ActiveSheet.QueryTables.Add(Connection:= _ "URL;*******/q/hp?s=UNIP.MI&a=0&b=1&c=2003&d=11&e=22&f=2009&g=d&z=66&y=66" _
, Destination:=Range("$A$3"))
.Name = "hp?s=UNIP.MI&a=0&b=1&c=2003&d=11&e=22&f=2009&g=d&z=66&y=66"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "21"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
‘ho inserito dentro un pulsante di aggiornamento situato nel foglio1 la query
Private Sub CommandButton1_Click()
‘ queste sono le variabili di riferimento dove prende i codici
TITOLO = Range(“A2”)
A1 = Range("AA1")
A2 = Range("AA2")
A3 = Range("AA3")
A4 = Range("AA4")
A5 = Range("AA5")
A6 = Range("AA6")
A7 = Range("AA7")
A8 = Range("AA8")
A9 = Range("AA9")
A10 = Range("AA10")
A11 = Range("AA11")
A12 = Range("AA12")
A13 = Range("AA13")
A14 = Range("AA14")
A15 = Range("AA15")
A16 = Range("AA16")
A17 = Range("AA17")
A18 = Range("AA18")
A19 = Range("AA19")
A20 = Range("AA20")
A21 = Range("AA21")
A22 = Range("AA22")
A23 = Range("AA23")
A24 = Range("AA24")
A25 = Range("AA25")
A26 = Range("AA26")
A27 = Range("AA27")
‘questi sono i riferimenti dove prende le celle di destinazione
AA = Range("AB1")
AA1 = Range("AB2")
AA2 = Range("AB3")
AA3 = Range("AB4")
AA4 = Range("AB5")
AA5 = Range("AB6")
AA6 = Range("AB7")
AA7 = Range("AB8")
AA8 = Range("AB9")
AA9 = Range("AB10")
AA10 = Range("AB11")
AA11 = Range("AB12")
AA12 = Range("AB13")
AA13 = Range("AB14")
AA14 = Range("AB15")
AA15 = Range("AB16")
AA16 = Range("AB17")
AA17 = Range("AB18")
AA18 = Range("AB19")
AA19 = Range("AB20")
AA20 = Range("AB21")
AA21 = Range("AB22")
AA22 = Range("AB23")
AA23 = Range("AB24")
AA24 = Range("AB25")
AA25 = Range("AB26")
AA26 = Range("AB27")
‘query che ho modificato la prima trance non ha codici
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;**********/q/hp?s=" & TITOLO _
, Destination:=Range(AA))
.Name = "hp?s=" & TITOLO
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "21"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
‘la seconda per il recupero ha bisogno di codici
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;********/q/hp?s=" & TITOLO & "&d=11&e=23&f=2009&g=d&a=0&b=1&c=2003&z=" & A1 & "&y=" & A1 _
, Destination:=Range(AA1))
.Name = "hp?s=" & TITOLO & "&d=11&e=23&f=2009&g=d&a=0&b=1&c=2003&z=" & A1 & "&y=" & A1
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "21"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
‘terza trance
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;*********/q/hp?s=" & TITOLO & "&d=11&e=23&f=2009&g=d&a=0&b=1&c=2003&z=" & A2 & "&y=" & A2 _
, Destination:=Range(AA2))
.Name = "hp?s=" & TITOLO & "&d=11&e=23&f=2009&g=d&a=0&b=1&c=2003&z=" & A2 & "&y=" & A2
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "21"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
‘ è così via fino alla fine delle trance di quotazioni
End Sub
|
Private Sub CommandButton1_Click()
FileDaAprire = Application.GetOpenFilename("Text Files (*.txt), *.txt")
If FileDaAprire = False Then Exit Sub
Dove = ("A5")
If Dove = "" Then Exit Sub
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & FileDaAprire & "", Destination:=Range(Dove))
.Name = FileDaAprire
.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 = xlTextQualifierSingleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub |
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;******/q/hp?s=ENI&d=11&e=23&f=2009&g=d&a=0&b=1&c=2003&z=66&y=66" _
, Destination:=Range("$A$1"))
.Name = "hp?s=ENI&d=11&e=23&f=2009&g=d&a=0&b=1&c=2003&z=66&y=66"
'prima parte della query il titolo rimane fisso per tutte
'il codice 66 cambia nella seconda query diventa 132
'la destinazione cambia in seconda query diventa A73 |
Sub calcola()
Dim TITOLO As String
Const CODICE = 70 '<----- Il CODICE è = a 70 (66 + 4)in quanto ho già aggiunto le 4 righe di spazio'
Dim NTrance As Integer
Dim RigaInizio As Integer
Set txTITOLO = UserForm1.TextBox3
Set txNTRANCE = UserForm1.TextBox5
'CICLO DI COPIA
'***************************
If txTITOLO.Text = "" Or txNTRANCE.Text = "" Then
MsgBox (" MANCANO I DATI NELLE CASELLE"), vbInformation, "DATI"
Exit Sub
End If
TITOLO = txTITOLO
NTrance = txNTRANCE
For i = 1 To NTrance
RigaInizio = ((i * CODICE) - 66)
Sheets("foglio1").Cells(RigaInizio - 1, 1).Select
Selection = txTITOLO
Sheets("FOGLIO1").Cells(RigaInizio, 1).Select
inserisci
'------- IN QUESTA AREA METTI I COMANDI DA ESEGUIRE ----------------------
'***********************************************************************
' q u e r y imortazione
'***********************************************************************
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;**Indirizzo sito**/q/hp?s=" & TITOLO & "&d=11&e=23&f=2009&g=d&a=0&b=1&c=2003&z=" & CODICE & "&y=" & CODICE _
, Destination:=Range(CODICE))
.Name = "hp?s=" & TITOLO & "&d=11&e=23&f=2009&g=d&a=0&b=1&c=2003&z=" & CODICE & "&y=" & CODICE
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "21"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
MsgBox (("TRANCE N. " & i & " COPIATA DA RIGA " & RigaInizio)), vbInformation, "ciclo for"
Next
End Sub
'********************************
Sub inserisci()
Set fgl2 = Sheets("foglio2")
Set zona = fgl2.Cells
'******************************************************************
dati = Array(fgl2.Cells(1, 1), fgl2.Cells(1, 2), fgl2.Cells(1, 3)) 'questi sono i valori che la query deve prendere per il tuo caso 66 quindi fino a ... fgl2.Cells(1,66)
'******************************************************************
Sheets("foglio1").Select
For i = 0 To 66
Cells(ActiveCell.Row, 1).Value = dati(i)
Cells(ActiveCell.Row, 1).Offset(1, 0).Select
Next
End Sub |
Sub calcola()
CARICA
Dim TITOLO As String
Dim NTrance As Integer
Dim RigaInizio As Integer
Set txTITOLO = UserForm1.Combo1
Set txntrance = UserForm1.Combo2
Dim D1, D2, D3, D4, DES As String
Dim T1, T2, T3, T4 As String
Dim A1, A2, A3 As String
D1 = "a" & 2
D2 = "A" & 77
D3 = "a" & 149
D4 = "a" & 221
A1 = Range("AA1")
A2 = Range("AA2")
A3 = Range("AA3")
If txTITOLO.Text = "" Or txntrance.Text = "" Then
MsgBox (" MANCANO I DATI NELLE CASELLE"), vbInformation, "DATI"
Exit Sub
End If
TITOLO = txTITOLO
Sheets("FOGLIO1").Cells(1, 1) = txTITOLO
If txntrance.Text = "TTOT" Then DES = D1
For i = 1 To 4
txntrance.Text = "T" & i
Select Case txntrance.Text
Case "T1"
Trance = "URL;******/q/hp?s=" & txTITOLO
If txntrance = "T1" Then
DES = D1
End If
Case "T2"
Trance = "URL;******/q/hp?s=" & txTITOLO & "&a=0&b=1&c=2003&d=11&e=22&f=2009&g=d&z=" & A1 & "&y=" & A1
If txntrance = "T2" Then
DES = D2
End If
Case "T3"
Trance = "URL;*****/q/hp?s=" & txTITOLO & "&a=0&b=1&c=2003&d=11&e=22&f=2009&g=d&z=" & A2 & "&y=" & A2
If txntrance = "T3" Then
DES = D3
End If
Case "T4"
Trance = "URL;******/q/hp?s=" & txTITOLO & "&a=0&b=1&c=2003&d=11&e=22&f=2009&g=d&z=" & A3 & "&y=" & A3
If txntrance = "T4" Then
DES = D4
End If
End Select |
