Option Explicit Private Sub CommandButton1_Click() 'test pour connaitre le nombre de classeur ouvert Dim NombreClasseur As Integer NombreClasseur = Workbooks.Count If NombreClasseur > 1 Then BoucleClasseurs End If End Sub Sub BoucleClasseurs() 'Définit une variable qui va représenter un classeur à chaque itération. Dim Wb As Workbook 'Boucle sur chaque classeur de l'application Excel For Each Wb In Application.Workbooks 'Ecrit le nom de chaque classeur dans la fenêtre d'exécution Ctrl+G MsgBox Wb.Name Next Wb End Sub
Declare Function GetCurrentProcessId Lib "kernel32" () As Long Function getProcessInfoXL() Dim Tbl_Process() Dim x As Integer ''On Error Resume Next Dim objProcess, process, strNameOfUser ComputerName = "." Set objProcess = GetObject("winmgmts:{impersonationLevel=impersonate}\" _ & ComputerName & "rootcimv2").ExecQuery("Select * From Win32_Process") For Each process In objProcess If process.Name <> "System Idle Process" And process.Name <> "System" Then If InStr(1, process.Name, "EXCEL") Then x = x + 1 ReDim Preserve Tbl_Process(1 To 2, 1 To x) Tbl_Process(1, x) = process.processId Tbl_Process(2, x) = process.Name End If End If Next Set objProcess = Nothing getProcessInfoXL = Tbl_Process End Function Sub test() Dim ListXLProcess() ' ID du process de l'excel en cours : currentID = GetCurrentProcessId() Debug.Print "Current Process : " & currentID ' Liste de tous les process EXCEL ListXLProcess = getProcessInfoXL() ' Kill Des process Sauf celui qui sert à la macro Nb_Process = UBound(ListXLProcess) - 1 'Debug.Print Nb_Process For p = 1 To Nb_Process process_ID = ListXLProcess(1, p) Debug.Print "Process : " & process_ID If process_ID <> currentID Then strKillPid = "TASKKILL /PID " & process_ID Shell sKillExcel, vbHide End If Next End Sub
Sub Notetraça() Dim i As Variant, j As Variant, m As Variant, n As Variant, s As Variant, p As Variant, total As Variant, r As Variant, f As Variant f = 1 Do While Worksheets("listeArticles").Cells(f, 2) <> "" f = f + 1 Loop i = 2 Do While Worksheets("Resultats").Cells(i, 2) <> "" j = 1 Do While Worksheets("DETAIL_V").Cells(j, 3) <> "" codearticlevente = Worksheets("DETAIL_V").Cells(j, 4) If Worksheets("DETAIL_V").Cells(j, 3).Value = Worksheets("Resultats").Cells(i, 2).Value Then m = 1 Do While m <= f If Worksheets("Resultats").Cells(i, 5) = Worksheets("listeArticles").Cells(m, 1) Then Exit Do Else m = m + 1 End If Loop lineStart = m n = m + 1 Do While n <= f If Worksheets("listeArticles").Cells(n, 1) <> "" Then Exit Do Else n = n + 1 End If Loop lineEnd = n - 1 For x = lineStart To lineEnd If codearticlevente = Worksheets("listeArticles").Cells(x, 2) Then Worksheets("DETAIL_V").Cells(j, 10) = 0 Exit For Else Worksheets("DETAIL_V").Cells(j, 10) = Worksheets("DETAIL_V").Cells(j, 8) End If Next x If Worksheets("DETAIL_V").Cells(j, 10) <> 0 Then If MsgBox("Article d'achat : " & Worksheets("Resultats").Cells(i, 5) & " Article de vente : " & Worksheets("DETAIL_V").Cells(j, 5) & vbCrLf & "Autoriser ?", vbQuestion + vbYesNo) <> vbYes Then Worksheets("DETAIL_V").Cells(j, 10) = Worksheets("DETAIL_V").Cells(j, 8) Worksheets("Resultats").Cells(i, 17) = Worksheets("Resultats").Cells(i, 17) & " + " & Worksheets("DETAIL_V").Cells(j, 8) & "kg " & Worksheets("DETAIL_V").Cells(j, 5).Value Else Worksheets("DETAIL_V").Cells(j, 10) = 0 End If End If End If j = j + 1 Loop i = i + 1 Loop s = 2 r = 2 starter = 1 Do While Worksheets("DETAIL_V").Cells(s, 3) <> "" If Worksheets("DETAIL_V").Cells(s, 3) <> Worksheets("DETAIL_V").Cells(s + 1, 3) Then total = 0 fin = s For p = starter To fin total = total + Worksheets("DETAIL_V").Cells(p, 10) Next p Worksheets("DETAIL_V").Cells(fin, 11) = total starter = s + 1 Do While Worksheets("Resultats").Cells(r, 2) <> "" If Worksheets("DETAIL_V").Cells(s, 3) = Worksheets("Resultats").Cells(r, 2) Then pourcentage = Worksheets("DETAIL_V").Cells(fin, 11) / Worksheets("Resultats").Cells(r, 10) If pourcentage <= 0.01 Then Worksheets("Resultats").Cells(r, 15) = 1 Exit Do End If If (pourcentage <= 0.02 And pourcentage > 0.01) Then Worksheets("Resultats").Cells(r, 15) = 0.75 Exit Do End If If (pourcentage <= 0.03 And pourcentage > 0.02) Then Worksheets("Resultats").Cells(r, 15) = 0.5 Exit Do End If If (pourcentage <= 0.04 And pourcentage > 0.03) Then Worksheets("Resultats").Cells(r, 15) = 0.25 Exit Do End If If pourcentage > 0.04 Then Worksheets("Resultats").Cells(r, 15) = 0 Exit Do End If End If r = r + 1 Loop End If s = s + 1 Loop End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionOption Explicit Private Sub CommandButton1_Click() 'test pour connaitre le nombre de classeur ouvert Dim NombreClasseur As Integer NombreClasseur = Workbooks.Count If NombreClasseur > 1 Then BoucleClasseurs End If End Sub Sub BoucleClasseurs() Dim nom As String 'Définit une variable qui va représenter un classeur à chaque itération. Dim Wb As Workbook 'Boucle sur chaque classeur de l'application Excel For Each Wb In Application.Workbooks 'Ecrit le nom de chaque classeur nom = Wb.Name If nom = "Classeur1.xls" Then 'mettre le nom du classeur en respectant le casse Workbooks("Classeur1.xls").Close 'ferme le classeur MsgBox "Le classeur " & nom & " estfermé" Else Exit Sub End If Next Wb End Sub