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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
Option Explicit
Sub reflectivité()
Dim WB As Workbook, Treatedfile As Workbook
Dim Openreference As Variant
Dim a As Integer, dc As Integer, i As Integer, numecelvide As Integer, j As Integer, min As Integer, max As Integer
Dim fichier() As String, chemin_enregistrement As String, somme As String
Dim runnumber As String
Dim photonpas As Single, somme1 As Single, photonpasref As Single, somme2 As Single
Dim Obj As OLEObject
Dim dl As Long
Dim pas As Double
Set WB = ThisWorkbook
WB.Worksheets(4).Visible = False
Application.ScreenUpdating = False
runnumber = InputBox("N° de run:")
If runnumber = "" Then Exit Sub
Openreference = Application.GetOpenFilename("", , "Reflectivity File Selection", , True) 'ouverture dela boite de dialogue Open avec filtre et affectation du chemin dans la variable
If VarType(Openreference) = vbBoolean Then Exit Sub
a = 1: j = 1
For a = 1 To UBound(Openreference)
Set Treatedfile = Application.Workbooks.Open(Openreference(a)) '(OpenFile, xlMSDOS)
fichier = Split(Treatedfile.Name, ".")
WB.Worksheets(2).Cells(a, 1).Value = fichier
WB.Worksheets(2).Cells(a, 2).Value = Treatedfile.Path
With Treatedfile
With Worksheets(1)
dl = .Range("A1000").End(xlUp).Row
dc = .Range("Z" & dl).End(xlToLeft).Column
numecelvide = .Range("B1").End(xlDown).Row
If a = 1 Then
.Range(.Cells(numecelvide, 1), .Cells(dl, dc)).Copy WB.Worksheets(3).Cells(3, j)
WB.Worksheets(3).Cells(2, j + 1).Value = fichier
WB.Worksheets(3).Cells(1, j).Value = "Longueur d'onde [nm]"
WB.Worksheets(3).Cells(1, j + 1).Value = "Réflectivité mesurée [%]"
j = j + 3
Else
.Range(.Cells(numecelvide, dc), .Cells(dl, dc)).Copy WB.Worksheets(3).Cells(3, j)
WB.Worksheets(3).Cells(2, j).Value = fichier
j = j + 2
End If
End With
.Close (False)
End With
Next a
' attribution des valeurs aux bornes pour le calcul de reff
min = InputBox("Longueur d'onde minimale en nm:", "Borne inférieure pour le calcul de la réflectivité effective")
max = InputBox("Longueur d'onde maximale en nm:", "Borne supérieure pour le calcul de la réflectivité effective")
With WB
With Worksheets(3)
dl = .Range("A1000").End(xlUp).Row 'cherche le nombre de ligne
dc = .Range("DD2").End(xlToLeft).Column 'cherche le nombre de colonne
pas = .Cells(dl - 1, 1).Value - .Cells(dl, 1).Value
.Range(.Cells(3, 1), .Cells(dl, dc)).Sort Key1:=.Cells(3, 1), Order1:=xlAscending, Header:=xlGuess
a = 2: j = 1
While a <= dc
i = Application.WorksheetFunction.Match(min, .Range(.Cells(1, 1), .Cells(dl, 1)))
For i = Application.WorksheetFunction.Match(min, .Range(.Cells(1, 1), .Cells(dl, 1))) To Application.WorksheetFunction.Match(max, .Range(.Cells(1, 1), .Cells(dl, 1)))
photonpas = pas * (WB.Worksheets(4).Cells(i, 2).Value)
photonpasref = pas * (WB.Worksheets(4).Cells(i, 2).Value) * (WB.Worksheets(3).Cells(i, a).Value)
If i = Application.WorksheetFunction.Match(min, .Range(.Cells(1, 1), .Cells(dl, 1))) Then
somme1 = photonpas
somme2 = photonpasref
Else
somme1 = somme1 + photonpas
somme2 = somme2 + photonpasref
End If
Next i
WB.Worksheets(2).Cells(j, 3).Value = (somme2 / somme1) / 100
j = j + 1: a = a + 2
Wend
.Cells.NumberFormat = "0.00"
.Cells.EntireColumn.AutoFit
End With
Worksheets(2).Activate
With Worksheets(2)
j = 1
For j = 1 To .Range("A1000").End(xlUp).Row
Worksheets(2).Range("D" & j).Activate
Set Obj = .OLEObjects.Add(ClassType:="Forms.CheckBox.1", Link:=False, DisplayAsIcon:=False)
With Obj
.Width = 10
.Object.Caption = ""
End With
Next j
.Rows("1:1").Insert
.Range("A1:C1") = Array("Fichier", "Emplacement", "Reff (" & min & " - " & max & " nm) [%]")
.Range("C1").Characters(2, 3).Font.Subscript = True
.Columns(3).NumberFormat = "0.0%"
.Cells.EntireColumn.AutoFit
.Rows(1).Font.Bold = True
.Select
End With
chemin_enregistrement = Application.GetSaveAsFilename("Reflectivity resume " & runnumber, ", *.xls")
WB.SaveAs (chemin_enregistrement)
End With
End Sub |
Partager