Option Explicit
'
Sub Fichier_vide()
Dim ws As Worksheet
For Each ws In Worksheets
With ws
If .Cells(1, 1).Value <> "" Then
.Cells(1, 1).CurrentRegion.ClearContents
End If
End With
Next
End Sub
'
Sub Donnees_fin()
If cal_sheet(Sheets("sbf_120")) = True Then
'sbf_120 / ' Continuer après que la feuille a été calculée
Sheets("sbf_120").Cells(1, 1).Formula = "=BQL(""Members('SBF120 INDEX')"", ""ID_ISIN,NAME"")"
End If
If cal_sheet(Sheets("dj600")) = True Then
'dj600 / ' Continuer après que la feuille a été calculée
Sheets("dj600").Cells(1, 1).Formula = "=BQL(""Members('SXXP INDEX')"", ""ID_ISIN,NAME"")"
End If
If cal_sheet(Sheets("sp_500")) = True Then
'sp_500 / ' Continuer après que la feuille a été calculée
Sheets("sp_500").Cells(1, 1).Formula = "=BQL(""Members('SPX INDEX')"", ""ID_ISIN,NAME"")"
End If
End Sub
'On fige les formules
Sub ConvertFormulasToValuesAllWorksheets()
Dim ws As Worksheet, rng As Range
For Each ws In ActiveWorkbook.Worksheets
For Each rng In ws.UsedRange
If rng.HasFormula Then
rng.Formula = rng.Value
End If
Next rng
Next ws
End Sub
'
Sub Mes_donnees()
Call Fichier_vide
Call Donnees_fin
Call ConvertFormulasToValuesAllWorksheets
End Sub
'Cette fonction renvoie Vrai lorsque la feuille active est complètement calculé
'si faux, il y a besoin de calculer encore une pause de 5 secondes est laissé pour effectuer les calcules
Function cal_sheet(ByVal ws As Worksheet) As Boolean
Dim tmp As Boolean
tmp = False
Dim c As Object
MsgBox ws.Name
ActiveSheet.Calculate
With ActiveSheet.UsedRange
Set c = .Find("request", LookIn:=xlValues)
If Not c Is Nothing Then
Application.OnTime Now + TimeValue("00:00:05"), "Donnees_fin"
tmp = False
Else
tmp = True
End If
End With
cal_sheet = tmp
End Function