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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
| Option Explicit
Dim inputFileName As String, inputFileNameLOADCASE As String, inputFileNamePATRAN As String, outputFileName As String
Dim startText As String, endText As String
Dim FSO, FSO1 As Object
Dim textFile As Object
Dim out_textFile As Object
Dim strligne As String
Dim p1 As Long, p2 As Long
Dim flight_name As String
Dim sub1, sub2 As String
Dim data As String
Dim ID1, ID2 As Double
Dim oTxt As Scripting.TextStream
Dim objFSO
Dim strFolder
Dim monfichier123 As Variant
Dim k As Integer
Dim directory123 As String
Dim lastRow As Long
Dim lastrow1 As Double
Dim MonFichier As Variant
Public Monclasseur As String
Dim i, numligne As Long
Dim duree As Date
Dim book As Workbook
Dim element As Integer
Dim xl, xr, xml, xmr, xm, resultXML, resultXMR, h, epsi As Double
Sub TestCalcul()
Application.ScreenUpdating = True
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
Set book = ActiveWorkbook
Cells.EntireColumn.Delete
duree = Now
Set FSO = CreateObject("Scripting.FileSystemObject")
inputFileNameLOADCASE = Application.GetOpenFilename("Text Files (*.xls), *.xls", Title:="Selectionner un fichier Load Case")
inputFileNamePATRAN = Application.GetOpenFilename("Text Files (*.rpt), *.rpt", Title:="Selectionner un fichier Patran")
Set objFSO = CreateObject("Scripting.FileSystemObject")
book.Activate
Worksheets(1).Activate
' renommer les cellules
With Worksheets(1)
.Range("E1") = "Facteur_1"
.Range("G1") = "Facteur_2"
.Range("H1") = "LC"
.Range("I1") = "LC_X"
.Range("J1") = "LC_Y"
.Range("K1") = "LC_Z"
.Range("M1") = "Sigma_Patran_X"
.Range("N1") = "Sigma_Patran_Y"
.Range("O1") = "Sigma_Patran_XY"
.Range("P1") = "LC_X_1g"
.Range("Q1") = "LC_Y_1g"
.Range("R1") = "LC_Z_1g"
.Range("S1") = "LC_X_S"
.Range("T1") = "LC_Y_S"
.Range("U1") = "LC_Z_S"
.Range("V1") = "LC_X"
.Range("W1") = "LC_Y"
.Range("X1") = "LC_Z"
.Range("Y1") = "Sigma_X"
.Range("Z1") = "Sigma_Y"
.Range("AA1") = "Sigma_XY"
.Range("AB1") = "Sigma_CC_Projetée"
.Range("AC1") = "Sigma_CC_Projetée_RainFlow"
.Range("AD1") = "alpha"
.Range("AE1") = "Max_Sigma_RainFlow"
.Range("AF1") = "Alpha_Max_Sigma_RainFlow"
.Range("AG1") = "Max_Sigma_RainFlow ^ 4.5"
.Range("AH1") = "Sigma_Equi_Projetée_1000_Vols"
'.Range("AI1") = "Containte équi 1000 vol "
End With
' ouvrir un fichier xls
MonFichier = inputFileNameLOADCASE
If MonFichier <> False Then
Workbooks.OpenText Filename:=inputFileNameLOADCASE, DataType:=xlDelimited, ConsecutiveDelimiter:=True, Space:=True
k = Range("J10").End(xlDown).Row
book.Worksheets(1).Range("H2:H" & k - 8).Value = ActiveSheet.Range("J10:J" & k).Value
book.Worksheets(1).Range("I2:I" & k - 8).Value = ActiveSheet.Range("AD10:AD" & k).Value
book.Worksheets(1).Range("J2:J" & k - 8).Value = ActiveSheet.Range("AE10:AE" & k).Value
book.Worksheets(1).Range("K2:K" & k - 8).Value = ActiveSheet.Range("AF10:AF" & k).Value
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
MonFichier = vbNullString
inputFileNameLOADCASE = vbNullString
End If
' ouvrir un fichier text
MonFichier = inputFileNamePATRAN
If MonFichier <> False Then
Workbooks.OpenText Filename:=inputFileNamePATRAN, DataType:=xlDelimited, ConsecutiveDelimiter:=True, Space:=True
book.Worksheets(1).Range("M2").Value = ActiveSheet.Range("D21").Value
book.Worksheets(1).Range("M3").Value = ActiveSheet.Range("D22").Value
book.Worksheets(1).Range("N2").Value = ActiveSheet.Range("E21").Value
book.Worksheets(1).Range("N3").Value = ActiveSheet.Range("E22").Value
book.Worksheets(1).Range("O2").Value = ActiveSheet.Range("F21").Value
book.Worksheets(1).Range("O3").Value = ActiveSheet.Range("F22").Value
ID1 = ActiveSheet.Range("C21")
ID2 = ActiveSheet.Range("C22")
startText = "1 HORIZONTAL_"
endText = "2 VERTICAL_"
sub1 = "Entity ID"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set textFile = FSO.OpenTextFile(inputFileNamePATRAN)
data = textFile.ReadAll
textFile.Close
p1 = InStr(data, startText) + Len(startText)
p2 = InStr(data, endText) + Len(endText)
If p1 > 0 And p2 > 0 Then
With book.Worksheets(1)
.Range("L2") = Mid(data, p1, 3)
.Range("L4") = Mid(data, p2, 3)
.Range("L1") = "Horizontal force" & " " & "ID" & " : " & ID1
.Range("L3") = "Vertical force" & " " & "ID" & " : " & ID2
End With
End If
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
End If
MonFichier = vbNullString
inputFileNamePATRAN = vbNullString
Set FSO = Nothing
Set textFile = Nothing
ID1 = vbNullChar
ID2 = 0
sub1 = vbNullString
startText = vbNullString
endText = vbNullString
data = vbNullString
p1 = 0
p2 = 0
ActiveSheet.Calculate
' ouvrir un fichier .fue
Line1:
Set objFSO = CreateObject("Scripting.FileSystemObject")
directory123 = "C:\temp\Results_Mon_Results"
If Not objFSO.FolderExists(directory123) Then
objFSO.CreateFolder (directory123)
End If
line3:
For k = 1 To 1000
Application.StatusBar = k & "/" & "1000"
MonFichier = "C:\Temp\OUT_VOL\" & k & ".txt"
If MonFichier <> False Then
Workbooks.OpenText Filename:=MonFichier, DataType:=xlDelimited, ConsecutiveDelimiter:=True, Space:=True
ActiveSheet.Rows(1).Delete
numligne = ActiveSheet.Range("B1").End(xlDown).Row
book.Worksheets(1).Range("A1").Value = ActiveSheet.Range("A1").Value
book.Worksheets(1).Range("B1:B" & numligne).Value = ActiveSheet.Range("B1:B" & numligne).Value
book.Worksheets(1).Range("C1:C" & numligne).Value = ActiveSheet.Range("C1:C" & numligne).Value
book.Worksheets(1).Range("D1:D" & numligne).Value = ActiveSheet.Range("D1:D" & numligne).Value
book.Worksheets(1).Range("E1:E" & numligne).Value = ActiveSheet.Range("E1:E" & numligne).Value
book.Worksheets(1).Range("F1:F" & numligne).Value = ActiveSheet.Range("F1:F" & numligne).Value
book.Worksheets(1).Range("G1:G" & numligne).Value = ActiveSheet.Range("G1:G" & numligne).Value
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
End If
ActiveSheet.Calculate
MonFichier = vbNullString
' rechercher les valeurs de 1g et S_A0
book.Worksheets(1).Activate
lastRow = Range("D2").End(xlDown).Row
Range("P2:P" & lastRow) = Application.IfError(Application.VLookup(Range("D2:D" & lastRow), Range("$H$2:$K$2", Range("$H$2:$K$2").End(xlDown)), 2, False), 0)
Range("Q2:Q" & lastRow) = Application.IfError(Application.VLookup(Range("D2:D" & lastRow), Range("$H$2:$K$2", Range("$H$2:$K$2").End(xlDown)), 3, False), 0)
Range("R2:R" & lastRow) = Application.IfError(Application.VLookup(Range("D2:D" & lastRow), Range("$H$2:$K$2", Range("$H$2:$K$2").End(xlDown)), 4, False), 0)
Range("S2:S" & lastRow) = Application.IfError(Application.VLookup(Range("F2:F" & lastRow), Range("$H$2:$K$2", Range("$H$2:$K$2").End(xlDown)), 2, False), 0)
Range("T2:T" & lastRow) = Application.IfError(Application.VLookup(Range("F2:F" & lastRow), Range("$H$2:$K$2", Range("$H$2:$K$2").End(xlDown)), 3, False), 0)
Range("U2:U" & lastRow) = Application.IfError(Application.VLookup(Range("F2:F" & lastRow), Range("$H$2:$K$2", Range("$H$2:$K$2").End(xlDown)), 4, False), 0)
lastrow1 = Range("D1").Value + 1
ActiveSheet.Calculate
' faire les calculs des load cases
''// ICI je mes des formules que je ne peux pas montrer pour des raisons de confidetialité
ActiveSheet.Calculate
'faire les calculs de sigma
''// ICI je mes des formules que je ne peux pas montrer pour des raisons de confidetialité
ActiveSheet.Calculate
' Méthode Dichotomie ( optimisation)
epsi = 1
xr = 150
xl = 0
Do While (xr - xl) > epsi
h = (xr - xl) / 3
xml = xl + h
xmr = xr - h
'ici formule avec variable xml
ActiveSheet.Calculate
'appelle à une autre macro pour la variable xml
ActiveSheet.Calculate
' ici formule avec variable xmr
ActiveSheet.Calculate
'appelle à une autre macro pour la variable xmr
ActiveSheet.Calculate
resultXML = Range("AC2").Value
resultXMR = Range("AE2").Value
If resultXML < resultXMR Then
xl = xml
Else
xr = xmr
End If
Loop
xm = (xr + xl) / 2
'ici formule pour la variable xm
ActiveSheet.Calculate
'appelle à une macro pour la variable xm
Range("AH" & k + 1) = xm
ActiveSheet.Calculate
Range("AI" & k + 1) = Range("AG" & k + 1) ^ 4.5
ActiveSheet.Calculate
DoEvents
Next k
Range("AJ" & k + 1).Formula = "=max(AH2:AH5000)"
If objFSO.FileExists("C:\temp\Results_Mon_Results\SIGeq_projection_1000.txt") Then
objFSO.DeleteFile ("C:\temp\Results_Mon_Results\SIGeq_projection_1000.txt")
End If
If Not objFSO.FileExists("C:\temp\Results_Mon_Results\SIGeq_projection_1000.txt") Then
objFSO.CreateTextFile ("C:\temp\Results_Mon_Results\SIGeq_projection_1000.txt")
End If
ActiveSheet.Calculate
' ici une formule
ActiveSheet.Calculate
Set oTxt = objFSO.OpenTextFile("C:\temp\Results_Mon_Results\SIGeq_projection_1000.txt", ForAppending, TristateUseDefault)
ActiveSheet.Calculate
oTxt.WriteLine Range("AK").Value
Set objFSO = Nothing
Set oTxt = Nothing
k = 0
book.Worksheets(1).Activate
Cells.EntireColumn.AutoFit
duree = Now - duree
MsgBox ("opération terminée" & vbCrLf & duree)
Application.StatusBar = False
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
ActiveSheet.DisplayPageBreaks = True
End Sub |
Partager