Ciao a tutti,
chiarisco il significato del titolo , ovvero ho un file che scarica alcuni dati di borsa , accade però che taluni Isin NON vengono scaricati , fermo restando che la pagina è la stessa quindi anche le conduzioni Html sono le stesse. Non riesco a capire il perchè oppure se c'è un errore nel VBA. Se qualcuno volesse dare una occhiata ... lo ringrazio da subito.
allego file e codice . grazie
[codeOption Explicit
Public Sub test2() '
Dim Html As MSHTML.HTMLDocument
Dim CollA As Object
Dim N As Long, I As Long
Dim dati As Variant
Dim dati1 As Variant
Dim intest As Variant
Dim MyIsin As String
Dim uR As Long
Dim R
Dim Ws1 As Worksheet
Set Ws1 = Sheets("Isin")
Ws1.Select
Ws1.Activate
Application.EnableEvents = False
uR = Ws1.Cells(Rows.Count, 1).End(xlUp).Row
Ws1.Range("B2:O" & uR).Clear
' codifica come stringa
Set Ws1 = Sheets("Isin")
Ws1.Select
Ws1.Activate
Application.EnableEvents = False
'
Call ControllaISIN
intest = Array("Isin", "Descrizione", "Ultimo", "Chiusura", "Variazione % ", "Valuta", "Lotto", "Cedola Periodale", "Cedola annua", "Rendimento a scadenza Lordo", "Rendimento a scadenza netto", _
"Rateo Lordo %", "Rateo Netto %", "Duration", "Mkt") ' la scadenza trovasi sulla scheda Dati completi "Scadenza", Come ci arrivo ???
Range("A1:O1") = intest
uR = Ws1.Cells(Rows.Count, 1).End(xlUp).Row
Ws1.Range("B2:O" & uR).Clear
' codifica come stringa
With Ws1
.Range("C2:N" & uR).NumberFormat = "@"
' --------------converti isin a maiuscolo-------------------------------
Dim X As Object
For Each X In Range("A2:A" & uR)
X.Value = UCase(X.Value)
Next
'----------------------------------->>>>>>>>>>>>>>>>---------------------------
Set Html = CreateObject("htmlfile")
With CreateObject("WINHTTP.WinHTTPRequest.5.1")
For N = 2 To uR
MyIsin = Cells(N, 1)
If MyIsin <> "" Then
'Provo su Mot:
.Open "GET", "https://www.borsaitaliana.it/borsa/obbligazioni/mot/btp/scheda/" & Cells(N, 1) & ".html?lang.it", False
'https://www.borsaitaliana.it/borsa/obbligazioni/mot/btp/scheda/" & Cells(N, 1) & ".html?lang=it", False
.send
Html.body.innerHTML = .responseText
Application.Wait Now + TimeValue("00:00:02") 'pausa di 1 secondi
'On Error Resume Next
Set CollA = Html.getElementsByClassName("t-text -right")
'On Error GoTo 0
If Not CollA Is Nothing Then
If CollA.Length > 5 Then '+++
'trovato su Mot
'gestisci i dati da Mot
On Error Resume Next ' questo non è possibile toglierlo
dati1 = Array(0, 0, 32, , 0, , 28, 27, 40, 41, 11, 12, 13, 14, 15, 29, 36)
For I = 2 To 17
Cells(N, I) = CollA(dati1(I)).innerText
Next I
On Error GoTo 0
'Debug.Print N, MyIsin
End If
End If
If Cells(N, 15) = "" Then
Cells(N, 15) = "TLX"
End If
On Error GoTo 0
'
End If
Next N
End With
End With
' --------------------converte testo a numero--------------------------------
For Each R In Sheets("Isin").UsedRange.SpecialCells(xlCellTypeConstants)
If IsNumeric(R) Then
R.Value = CSng(R.Value)
R.NumberFormat = "0.00"
End If
Next
'
Range("C2:D" & uR).NumberFormat = "#,##0.00"
Range("F2:F" & uR).NumberFormat = "#,##"
End Sub
][/code]
https://limewire.com/d/OhFIz#0bXSnXGmXP

