Condividi:        

I Vostri Lavori - Gestione Portafoglio Fondi d'investimento

Vuoi potenziare i tuoi documenti Word? Non sai come si fa una macro in Excel? Devi creare una presentazione in PowerPoint?
Oppure sei passato a OpenOffice e non sei sicuro di come lavorare al meglio?

Moderatori: Anthony47, Flash30005

I Vostri Lavori - Gestione Portafoglio Fondi d'investimento

Postdi BG66 » 29/03/21 10:13

Gestione Portafoglio Fondi d'investimento
File Excel per il monitoraggio delle performance dei fondi su borsaitaliana.it
https://www.dropbox.com/scl/fi/vssx29t0jlbldwpciorlk/Portafoglio_fondi-V0.xlsx?dl=0&rlkey=zjm2ux4wzfpi2kiuq1nl8ygk6
BG66
Excel2016
Avatar utente
BG66
Utente Senior
 
Post: 333
Iscritto il: 20/08/16 07:44

Sponsor
 

Re: I Vostri Lavori - Gestione Portafoglio Fondi d'investime

Postdi Anthony47 » 30/03/21 13:44

Grazie Gene per la condivisione
Tuttavia il "pulsante" richiede una macro che non e' presente nel file allegato (d'altra parte si tratta di un ".xlsx"), puoi integrarla?

Ciao
Avatar utente
Anthony47
Moderatore
 
Post: 19563
Iscritto il: 21/03/06 16:03
Località: Ivrea

Gestione Portafoglio Fondi d'investimento

Postdi BG66 » 30/03/21 15:55

Ciao Anthony,
dalle mie parti si dice "chi non ha testa abbia gambe"
Riallego link e stavolta al file corretto.
https://www.dropbox.com/scl/fi/sd0uduna8fv6n7ayd1em7/Portafoglio_fondi-V0.xlsm?dl=0&rlkey=m32pa9fj1kwq6wyl9gxtyqyk7

Alla prossima
Gene
BG66
Excel2016
Avatar utente
BG66
Utente Senior
 
Post: 333
Iscritto il: 20/08/16 07:44

Re: I Vostri Lavori - Gestione Portafoglio Fondi d'investime

Postdi Anthony47 » 31/03/21 16:00

Grazie per la condivisione!
Avatar utente
Anthony47
Moderatore
 
Post: 19563
Iscritto il: 21/03/06 16:03
Località: Ivrea

Re: I Vostri Lavori - Gestione Portafoglio Fondi d'investime

Postdi brtbrn » 10/02/25 18:21

Ciao Anthony,
eccoci qui su l'apposito thread.
Da questo file messo gentilmente a disposizione, ho fatto (a tentativi) alcune variazioni alla Sub per poter avere il prezzo da BI ANCHE delle obbligazioni.

Innanzitutto non è stato possibile utilizzare l'altra Sub che mi hai messo gentilmente a disposizione, primo perchè yahoo non ha le quotazioni di questi strumenti e, secondo, per i motivi che ti vado a scrivere.

La prima anomalia (rispetto alla sub originale per i fondi), è che nel caso delle obbligazioni, il link da cui parte la ricerca è diverso sia per il codice dell'obbligazione, sia, purtroppo, anche per il mercato in cui è trattato questo strumento.
La seconda anomalia è che BI, a seconda di quale mercato (MOT o TLX) vengono trattate le obbligazioni, ha dei "layout" diversi di impaginazione dati WEB.

ti riporto due strumenti con gli appositi link come esempio:
https://www.borsaitaliana.it/borsa/obbl ... ml?lang=it
https://www.borsaitaliana.it/borsa/obbl ... ml?lang=it
Come vedi, la prima e l'ultima parte della stringa è uguale; la differenza sta nel mercato in cui viene trattato lo strumento.

Per rimediare a questa differenza, partendo dal codice trovato sul file, ho fatto due sub - una per le obbligazioni trattate su MOT ed una per quelle trattate su TLX - ed ovviamente due fogli distinti in cui applicare le sub.

Io vorrei poter unificare il foglio su cui sono elencati i link che richiamano le sub, ossia dire alla sub di far partire un codice (anzichè un altro) a seconda che sul link di partenza vi sia la stringa MOT o TLX... oppure, al limite, da una colonna di appoggio (in cui riportare il mercato MOT o TLX di quello strumento) che faccia da discriminante.

E' possibile?

La sub per il mercato MOT:

Codice: Seleziona tutto
Sub ScanObbMOT()
Dim IE As Object, myF As Object, I As Long
'
For I = 2 To Cells(Rows.Count, 2).End(xlUp).Row
    myUrl = Cells(I, 2)             'L'url della pagina da accedere
    If InStr(1, myUrl, "http", vbTextCompare) = 1 Then
        'Se url valido, apre tramite InternetExplorer...
        If IE Is Nothing Then Set IE = CreateObject("InternetExplorer.Application")
        With IE
            .Visible = False        '...nascondi IE
            .navigate myUrl         '....vai all'url
            Sleep 100               '
            Do While .Busy: DoEvents: Sleep (20): Loop              'Attesa not busy
            Do While .readyState <> 4: DoEvents: Sleep (20): Loop   'Attesa document
        End With
        Sleep (100)                 'Stabilizza
        'Cerca le voci di interesse
        On Error Resume Next
            Set myF = IE.document.getElementsByClassName("w-999")
            Cells(I, "C").Value = (myF(0).getElementsByTagName("h1")(0).innerText)        'INTESTAZIONE (Descrizione)
            Cells(I, "D").Value = (myF(0).getElementsByTagName("strong")(0).innerText)    'quotazione
            ' Cells(I, "E").Value = (myF(0).getElementsByTagName("strong")(1).innerText)   'variazione
            Set myF = IE.document.getElementsByClassName("w-999__bcol")
            Cells(I, "F").Value = myF(0).getElementsByTagName("strong")(1).innerText       'data
            Set myF = IE.document.getElementsByTagName("table")
            ' Cells(I, "H").Value = (myF(1).getElementsByTagName("td")(3).innerText)       'Tabella DATI MERCATO(Min Oggi)
            Cells(I, "H").Value = (myF(2).getElementsByTagName("td")(11).innerText)       'Tabella RENDIMENTI EFFETTIVI (Prezzo di riferimento)
            Cells(I, "I").Value = (myF(2).getElementsByTagName("td")(13).innerText)       'Tabella RENDIMENTI EFFETTIVI (Data di riferimento)
            ' Cells(I, "H").Value = (myF(2).getElementsByTagName("td")(1).innerText)       'Tabella RENDIMENTI EFFETTIVI (Rendimento effettivo a scadenza lordo)
            ' Cells(I, "I").Value = (myF(2).getElementsByTagName("td")(5).innerText)       'Tabella RENDIMENTI EFFETTIVI (Rateo Lordo)
            ' Cells(I, "J").Value = (myF(2).getElementsByTagName("td")(7).innerText)       'Tabella RENDIMENTI EFFETTIVI (Rateo Netto)
            ' Cells(I, "K").Value = (myF(2).getElementsByTagName("td")(9).innerText)       'Tabella RENDIMENTI EFFETTIVI (Duration modificata)
            ' Cells(I, "H").Value = (myF(3).getElementsByTagName("td")(1).innerText)       'Tabella CONTRATTI(2^ Riga, 2^ Cella)
            Cells(I, "A").Value = (myF(4).getElementsByTagName("td")(1).innerText)        'Tabella INFO STRUMENTO(ISIN)
            Cells(I, "G").Value = (myF(4).getElementsByTagName("td")(17).innerText)       'Tabella INFO STRUMENTO(Valuta)
            Set myF = IE.document.getElementsByClassName("l-grid__row")
            gest = myF(6).innerText
            Cells(I, "L") = Application.WorksheetFunction.Clean(Split(gest, Chr(10), , vbTextCompare)(5))
        On Error GoTo 0
    End If
Next I
'Chiusura
On Error Resume Next
IE.Quit
Set IE = Nothing
End Sub


La sub per il mercato TLX:

Codice: Seleziona tutto
Sub ScanObbTLX()
Dim IE As Object, myF As Object, I As Long
'
For I = 2 To Cells(Rows.Count, 2).End(xlUp).Row
    myUrl = Cells(I, 2)             'L'url della pagina da accedere
    If InStr(1, myUrl, "http", vbTextCompare) = 1 Then
        'Se url valido, apre tramite InternetExplorer...
        If IE Is Nothing Then Set IE = CreateObject("InternetExplorer.Application")
        With IE
            .Visible = False        '...nascondi IE
            .navigate myUrl         '....vai all'url
            Sleep 100               '
            Do While .Busy: DoEvents: Sleep (20): Loop              'Attesa not busy
            Do While .readyState <> 4: DoEvents: Sleep (20): Loop   'Attesa document
        End With
        Sleep (100)                 'Stabilizza
        'Cerca le voci di interesse
        On Error Resume Next
            Set myF = IE.document.getElementsByClassName("w-999")
            Cells(I, "C").Value = (myF(0).getElementsByTagName("h1")(0).innerText)         'Descrizione(INTESTAZIONE)
            Cells(I, "D").Value = (myF(0).getElementsByTagName("strong")(0).innerText)     'quotazione
            ' Cells(I, "E").Value = (myF(0).getElementsByTagName("strong")(1).innerText)     'variazione
            Set myF = IE.document.getElementsByClassName("w-999__bcol")
            ' Cells(I, "F").Value = (myF(0).getElementsByTagName("strong")(1).innerText)     'data
            Set myF = IE.document.getElementsByTagName("table")
            ' Cells(I, "L").Value = (myF(4).getElementsByTagName("td")(4).innerText)     'Tabella CONTRATTI (2^riga, 2^ cella)
            ' Cells(I, "M").Value = (myF(3).getElementsByTagName("td")(1).innerText)     'Tabella RENDIMENTI EFFETTIVI (Rendimento effettivo a scadenza lordo)
            ' Cells(I, "N").Value = (myF(3).getElementsByTagName("td")(5).innerText)     'Rateo Lordo
            ' Cells(I, "O").Value = (myF(3).getElementsByTagName("td")(7).innerText)     'Rateo Netto
            ' Cells(I, "P").Value = (myF(3).getElementsByTagName("td")(9).innerText)     'Duration modificata
            Cells(I, "A").Value = (myF(1).getElementsByTagName("td")(5).innerText)     'Tabella DATI MERCATO (ISIN)
            Cells(I, "G").Value = (myF(1).getElementsByTagName("td")(11).innerText)    'Tabella DATI MERCATO (Valuta)
            Cells(I, "F").Value = (myF(0).getElementsByTagName("td")(7).innerText)     'Tabella DATI MERCATO (Data e Ora)
            Cells(I, "H").Value = (myF(3).getElementsByTagName("td")(11).innerText)    'Tabella RENDIMENTI EFFETTIVI (Prezzo di riferimento)
            Cells(I, "I").Value = (myF(3).getElementsByTagName("td")(13).innerText)    'Tabella RENDIMENTI EFFETTIVI (Data di riferimento)
            Set myF = IE.document.getElementsByClassName("l-grid__row")
            gest = myF(6).innerText
            Cells(I, "L") = Application.WorksheetFunction.Clean(Split(gest, Chr(10), , vbTextCompare)(5))
        On Error GoTo 0
    End If
Next I
'Chiusura
On Error Resume Next
IE.Quit
Set IE = Nothing
End Sub


Grazie anticipatamente!
brtbrn
Utente Junior
 
Post: 35
Iscritto il: 05/01/25 18:41

Re: I Vostri Lavori - Gestione Portafoglio Fondi d'investime

Postdi Anthony47 » 11/02/25 09:01

Questa macro ibrida prevede che in colonna B ci sia il codice del titolo, e in colonna A il mercato (MOT o TLX).
Codice: Seleziona tutto
Sub ScanBoth()
Dim IE As Object, myF As Object, I As Long
Dim MOTb As String, TLXb As String, myUrl As String
'
For I = 2 To Cells(Rows.Count, 2).End(xlUp).Row
    If Cells(I, 1) = "MOT" Then
        myUrl = Replace("https://www.borsaitaliana.it/borsa/obbligazioni/mot/btp/scheda/##@@##.html?lang=it", "##@@##", Cells(I, 2), , , vbTextCompare)
    ElseIf Cells(I, 1) = "TLX" Then
        myUrl = Replace("https://www.borsaitaliana.it/borsa/obbligazioni/eurotlx/scheda/##@@##.html?lang=it", "##@@##", Cells(I, 2), , , vbTextCompare)
    Else
        myUrl = ""
    End If
'    myUrl = Cells(I, 2)             'L'url della pagina da accedere
    If InStr(1, myUrl, "http", vbTextCompare) = 1 Then
        'Se url valido, apre tramite InternetExplorer...
        If IE Is Nothing Then Set IE = CreateObject("InternetExplorer.Application")
        With IE
        .Visible = True
'            .Visible = False        '...nascondi IE
            .navigate myUrl         '....vai all'url
            Sleep 100               '
            Do While .Busy: DoEvents: Sleep (20): Loop              'Attesa not busy
            Do While .readyState <> 4: DoEvents: Sleep (20): Loop   'Attesa document
        End With
        Sleep (100)                 'Stabilizza
        DoEvents
        If Cells(I, 1) = "MOT" Then
            On Error Resume Next
            Set myF = IE.document.getElementsByClassName("w-999")
            Cells(I, "C").Value = (myF(0).getElementsByTagName("h1")(0).innerText)        'INTESTAZIONE (Descrizione)
            Cells(I, "D").Value = (myF(0).getElementsByTagName("strong")(0).innerText)    'quotazione
            ' Cells(I, "E").Value = (myF(0).getElementsByTagName("strong")(1).innerText)   'variazione
            Set myF = IE.document.getElementsByClassName("w-999__bcol")
            Cells(I, "F").Value = myF(0).getElementsByTagName("strong")(1).innerText       'data
            Set myF = IE.document.getElementsByTagName("table")
            ' Cells(I, "H").Value = (myF(1).getElementsByTagName("td")(3).innerText)       'Tabella DATI MERCATO(Min Oggi)
            Cells(I, "H").Value = (myF(2).getElementsByTagName("td")(11).innerText)       'Tabella RENDIMENTI EFFETTIVI (Prezzo di riferimento)
            Cells(I, "I").Value = (myF(2).getElementsByTagName("td")(13).innerText)       'Tabella RENDIMENTI EFFETTIVI (Data di riferimento)
            ' Cells(I, "H").Value = (myF(2).getElementsByTagName("td")(1).innerText)       'Tabella RENDIMENTI EFFETTIVI (Rendimento effettivo a scadenza lordo)
            ' Cells(I, "I").Value = (myF(2).getElementsByTagName("td")(5).innerText)       'Tabella RENDIMENTI EFFETTIVI (Rateo Lordo)
            ' Cells(I, "J").Value = (myF(2).getElementsByTagName("td")(7).innerText)       'Tabella RENDIMENTI EFFETTIVI (Rateo Netto)
            ' Cells(I, "K").Value = (myF(2).getElementsByTagName("td")(9).innerText)       'Tabella RENDIMENTI EFFETTIVI (Duration modificata)
            ' Cells(I, "H").Value = (myF(3).getElementsByTagName("td")(1).innerText)       'Tabella CONTRATTI(2^ Riga, 2^ Cella)
            Cells(I, "A").Value = (myF(4).getElementsByTagName("td")(1).innerText)        'Tabella INFO STRUMENTO(ISIN)
            Cells(I, "G").Value = (myF(4).getElementsByTagName("td")(17).innerText)       'Tabella INFO STRUMENTO(Valuta)
            Set myF = IE.document.getElementsByClassName("l-grid__row")
            gest = myF(6).innerText
            Cells(I, "L") = Application.WorksheetFunction.Clean(Split(gest, Chr(10), , vbTextCompare)(5))
            On Error GoTo 0
        Else
        'TLX
            On Error Resume Next
            Set myF = IE.document.getElementsByClassName("w-999")
            Cells(I, "C").Value = (myF(0).getElementsByTagName("h1")(0).innerText)         'Descrizione(INTESTAZIONE)
            Cells(I, "D").Value = (myF(0).getElementsByTagName("strong")(0).innerText)     'quotazione
            ' Cells(I, "E").Value = (myF(0).getElementsByTagName("strong")(1).innerText)     'variazione
            Set myF = IE.document.getElementsByClassName("w-999__bcol")
            ' Cells(I, "F").Value = (myF(0).getElementsByTagName("strong")(1).innerText)     'data
            Set myF = IE.document.getElementsByTagName("table")
            ' Cells(I, "L").Value = (myF(4).getElementsByTagName("td")(4).innerText)     'Tabella CONTRATTI (2^riga, 2^ cella)
            ' Cells(I, "M").Value = (myF(3).getElementsByTagName("td")(1).innerText)     'Tabella RENDIMENTI EFFETTIVI (Rendimento effettivo a scadenza lordo)
            ' Cells(I, "N").Value = (myF(3).getElementsByTagName("td")(5).innerText)     'Rateo Lordo
            ' Cells(I, "O").Value = (myF(3).getElementsByTagName("td")(7).innerText)     'Rateo Netto
            ' Cells(I, "P").Value = (myF(3).getElementsByTagName("td")(9).innerText)     'Duration modificata
''            Cells(I, "A").Value = (myF(1).getElementsByTagName("td")(5).innerText)     'Tabella DATI MERCATO (ISIN)
            Cells(I, "G").Value = (myF(1).getElementsByTagName("td")(11).innerText)    'Tabella DATI MERCATO (Valuta)
            Cells(I, "F").Value = (myF(0).getElementsByTagName("td")(7).innerText)     'Tabella DATI MERCATO (Data e Ora)
            Cells(I, "H").Value = (myF(3).getElementsByTagName("td")(11).innerText)    'Tabella RENDIMENTI EFFETTIVI (Prezzo di riferimento)
            Cells(I, "I").Value = (myF(3).getElementsByTagName("td")(13).innerText)    'Tabella RENDIMENTI EFFETTIVI (Data di riferimento)
            Set myF = IE.document.getElementsByClassName("l-grid__row")
            gest = myF(6).innerText
            Cells(I, "L") = Application.WorksheetFunction.Clean(Split(gest, Chr(10), , vbTextCompare)(5))
            On Error GoTo 0
        End If
    End If
Next I
'Chiusura
On Error Resume Next
IE.Quit
Set IE = Nothing
End Sub

Le righe commentate possono ovviamente essere eliminate
Avatar utente
Anthony47
Moderatore
 
Post: 19563
Iscritto il: 21/03/06 16:03
Località: Ivrea

Re: I Vostri Lavori - Gestione Portafoglio Fondi d'investime

Postdi brtbrn » 11/02/25 17:34

Perfetto Anthony, grazie 1000!

una curiosità: ho visto che nelle tue sub, lasci sempre visibile IE (mentre io di solito lo nascondo). C'è un motivo o un utilità particolare per cui preferisci lasciarlo visibile?
brtbrn
Utente Junior
 
Post: 35
Iscritto il: 05/01/25 18:41

Re: I Vostri Lavori - Gestione Portafoglio Fondi d'investime

Postdi Anthony47 » 11/02/25 22:11

Lascio IE visibile perchè l'utente lo posso chiudere nei casi in cui la macro si interrompe in modo non pulito; altrimenti a fine giornata potresti, in qualche circostanza limite, trovarti con decine di sessioni aperte senza averne informazione
Avatar utente
Anthony47
Moderatore
 
Post: 19563
Iscritto il: 21/03/06 16:03
Località: Ivrea


Torna a Applicazioni Office Windows


Topic correlati a "I Vostri Lavori - Gestione Portafoglio Fondi d'investimento":

gestione di onedrive
Autore: themisterx
Forum: Software Windows
Risposte: 8
gestione di whatsapp
Autore: themisterx
Forum: Discussioni
Risposte: 3

Chi c’è in linea

Visitano il forum: Nessuno e 34 ospiti