Ciao Andrea,
Grazie per la tua risposta Norman!
Ho creato un file tramite word con esclusivamente l'indirizzo web; dopodiché ho salvato il file in formato .iqy.
Tuttavia ora ho difficoltà a trovare il comando che mi dici nella scheda "dati": purtroppo non vedo alcun comando "carica dati esterni > esegui query salvata". Tutto ciò che vedo nella scheda dati è quello che si vede nell'immagine che segue:
Inoltre se seleziono "nuova query da database" mi appaiono solo due opzioni: "ODBC SQL server" e "Da database" (ho provato a selezionare "Da database" e mi esce il seguente messaggio di errore: "Microsoft Excel non riesce a completare
l'operazione perché Gestione driver ODBC non è installato. Per installare Gestione driver ODBC, eseguire il programma di installazione e installare il driver di database per il tipo di database a cui si vuole accedere.")
Mi trovo in una situazione piuttosto difficile in quanto non possiedo un Mac e le mie versioni di Excel sono inglesi. Per caso, e insolitamente, per un paio di giorni ho avuto accesso ad un Mac ma esso e suo padrone sono andati via. Poi. la versione di Office
sul Mac era Office 2011. Mi aspetto di avere il piacere discutibile di rinnovare la mia conoscenza di quel Mac in un paio di giorni.
Nel frattempo, prova la seguente macro che, per gli scopi di dimostrarzione, scarica i dati storici relativi ai prezzi delle azioni di una società.
'=========>>
Option Explicit
'--------->>
Public Sub Tester()
Dim WB As Workbook
Dim EseguiQuerySH As Worksheet, ReportSH As Worksheet
Dim rngStartDate As Range, rngEndDate As Range
Dim destRng As Range, rngData As Range, rngSimboloAzionari As Range
Dim dStartDate As Date, dEndDate As Date
Dim sSimbolo As String, sUrl As String
Dim QTable As QueryTable
Dim LRow As Long
Const sFoglioEseguiQuery As String = "Esegui_Query" '<<=== Modifica
Const sFoglioReport As String = "REPORT"
'<<=== Modifica
Const sCellaSimbolo As String = "D10"
'<<=== Modifica
Const sCellaInizio As String = "D11"
'<<=== Modifica
Const sCellaFine As String = "D12"
'<<=== Modifica
Const sBaseUrl = _
"**http://finance.google.com/finance/historical?q=**" '<<=== Modifica
Set WB = ThisWorkbook
With WB
Set EseguiQuerySH = .Sheets(sFoglioEseguiQuery)
Set ReportSH = .Sheets(sFoglioReport)
End With
On Error GoTo XIT
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.Calculation = xlCalculationManual
End With
With EseguiQuerySH
Set rngSimboloAzionari = .Range(sCellaSimbolo)
Set rngStartDate = .Range(sCellaInizio)
Set rngEndDate = .Range(sCellaFine)
End With
dStartDate = rngStartDate.Value
dEndDate = rngEndDate.Value
sSimbolo = rngSimboloAzionari.Value
With ReportSH
Set destRng = .Range("A1")
.UsedRange.Cells.ClearContents
sUrl = sBaseUrl & sSimbolo
sUrl = sUrl & "&startdate=" _
& MonthName(Month(dStartDate), True) & _
"+" & Day(dStartDate) & "+" _
& Year(dStartDate) & _
"&enddate=" _
& MonthName(Month(dEndDate), True) & _
"+" & Day(dEndDate) & "+" _
& Year(dEndDate) & "&output=csv"
Set QTable = .QueryTables.Add( _
Connection:="URL;" & sUrl, _
Destination:=destRng)
With QTable
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
End With
With destRng
.CurrentRegion.Columns(1).TextToColumns _
Destination:=.Cells(1), _
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=True, _
Semicolon:=False, _
Comma:=True, _
Space:=False, _
other:=False
End With
.Columns("A:G").ColumnWidth = 12
LRow = LastRow(ReportSH, .Columns("A:A"))
Set rngData = .Range("A1:G" & LRow)
With rngData
.EntireColumn.ColumnWidth = 12
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
End With
With .Sort
.SortFields.Add _
Key:=rngData.Columns(1), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
.SetRange rngData
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
.SortFields.Clear
End With
End With
XIT:
On Error GoTo XIT
With Application
.ScreenUpdating = True
.DisplayAlerts = True
.Calculation = xlCalculationAutomatic
End With
End Sub
'--------->>
Public Function LastRow(SH As Worksheet, _
Optional rng As Range, _
Optional minRow As Long = 1, _
Optional sPassword As String)
Dim bProtected As Boolean
With SH
If rng Is Nothing Then
Set rng = .Cells
End If
bProtected = .ProtectContents = True
If bProtected Then
Application.ScreenUpdating = False
.Unprotect Password:=sPassword
End If
End With
On Error Resume Next
LastRow = rng.Find(What:="*", _
after:=rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
If LastRow < minRow Then
LastRow = minRow
End If
If bProtected Then
SH.Protect Password:=sPassword, _
UserInterfaceOnly:=True
End If
Application.ScreenUpdating = True
End Function
'<<=========
Potresti scaricare il mio file di prova Andrea20171030.xlsm
===
Regards,
Norman
