1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| Sub CoursForces(EstForce As Boolean)
Dim fichierMacro As Workbook, currentWB As Workbook
Dim cheminFichierCoursForces As String, nomFichierCoursForces As String
Dim nbLignes As Long, compteur As Long
Dim TAB_COURS_FORCES() As TAB_COURS_FORCES
Dim zoneCoursForces As Range
Dim celluleCoursForces As Range
Dim dateValorisationOPC As Date
Application.ScreenUpdating = False
Set fichierMacro = ActiveWorkbook
Set zoneCoursForces = Range(Cells(5, 12), Cells(14, 14))
Set celluleCoursForces = Range(Cells(1, 13), Cells(1, 13))
ActiveWorkbook.Names.Add Name:="ZoneCoursForces", RefersTo:=zoneCoursForces
ActiveWorkbook.Names.Add Name:="celluleCoursForces", RefersTo:=celluleCoursForces
Cells(3, 14).ClearContents
cheminFichierCoursForces = "P:\MIDDLE\Referentiel valeurs"
nomFichierCoursForces = "Cours forcés"
' If CheckBox1.Value = True Then
If EstForce = True Then
If MsgBox("Voulez-vous vraiment forcer les cours des fonds ?", vbYesNo, "Demande de confirmation") = vbYes Then
celluleCoursForces.Value = "oui"
zoneCoursForces.Range(Cells(1, 3), Cells(zoneCoursForces.Rows.Count, 3)).ClearContents
Application.DisplayAlerts = False
If OuvrirFichier(cheminFichierCoursForces, nomFichierCoursForces) = True Then
Application.DisplayAlerts = True
Set currentWB = ActiveWorkbook
currentWB.Activate
dateValorisationOPC = Cells(2, 3)
nbLignes = currentWB.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
ReDim TAB_COURS_FORCES(1 To Range(Cells(2, 1), Cells(nbLignes, 1)).Count) As TAB_COURS_FORCES
For i = 2 To nbLignes
compteur = compteur + 1
TAB_COURS_FORCES(compteur).ISIN = currentWB.Sheets(1).Cells(i, 2)
TAB_COURS_FORCES(compteur).DATE = currentWB.Sheets(1).Cells(i, 3)
TAB_COURS_FORCES(compteur).VL = currentWB.Sheets(1).Cells(i, 4)
Next i
Application.DisplayAlerts = False
currentWB.Close
Application.DisplayAlerts = True
nbLignes = Empty
Cells(3, 14) = dateValorisationOPC
For i = 1 To zoneCoursForces.Rows.Count
For iP = 1 To UBound(TAB_COURS_FORCES)
If zoneCoursForces.Cells(i, 2) = TAB_COURS_FORCES(iP).ISIN Then
If TAB_COURS_FORCES(iP).VL <> 0 Then
zoneCoursForces.Cells(i, 3) = TAB_COURS_FORCES(iP).VL
Else
zoneCoursForces.Cells(i, 3) = ""
End If
Exit For
End If
Next iP
Next i
Else
MsgBox "Le fichier des cours forcés est introuvable !"
fichierMacro.ActiveSheet.CaseACocher.Value = 0
' CheckBox1.Value = 0
celluleCoursForces.Value = "non"
Exit Sub
End If
Else
' CheckBox1.Value = 0
fichierMacro.ActiveSheet.CaseACocher.Value = 0
celluleCoursForces.Value = "non"
zoneCoursForces.Range(Cells(1, 3), Cells(zoneCoursForces.Rows.Count, 3)).ClearContents
Exit Sub
End If
Else
celluleCoursForces.Value = "non"
zoneCoursForces.Range(Cells(1, 3), Cells(zoneCoursForces.Rows.Count, 3)).ClearContents
End If
Application.ScreenUpdating = True
End Sub |