0

I created a function and a userform for update the % of my progress bar depending of where the code is. But the problem is that the progress bar don't update alone, it updates only when i close it. (it open a new progress bar with the next %)

This is the userform

Private Sub UserForm_Activate()

    
    UserForm1.Height = 121.5

                progression = taille_progressbar
                Image_barre.Width = progression * 1.5
                Label_barre.Caption = progression & "%"
                DoEvents
Application.ScreenUpdating = True
    UserForm1.Height = 136.5

End Sub

This is the call

taille_progressbar = 0
            UserForm1.Show
            
            cn.Open (ConnectionString)
            rs.Open "TRUNCATE Direction_Prix_proxi.prix_crf;", cn
            rs.Open "TRUNCATE Direction_Prix_proxi.prix_crf_exp;", cn
            rs.Open "TRUNCATE Direction_Prix_proxi.prix_int_exp;", cn
            rs.Open "TRUNCATE Direction_Prix_proxi.prix_int_cnt;", cn
            rs.Open "TRUNCATE Direction_Prix_proxi.prix_u;", cn
        
                    
            rs.Open "LOAD DATA LOCAL INFILE '\tomatisation\\prix_concurrents.csv" & _
                    "' INTO TABLE direction_prix_proxi.prix_crf FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n' IGNORE 2 LINES" & _
                    " (SIGMA, @PRIX) set PRIX= replace(@PRIX, ',','.');", cn
        
            rs.Open "Delete FROM direction_prix_proxi.prix_crf WHERE (SIGMA = 0);", cn
            
            rs.Open "UPDATE direction_prix_proxi.matrice_sigma sgm INNER JOIN direction_prix_proxi.prix_crf ref on sgm.SIGMA = ref.SIGMA SET sgm.prix_crf_cty = ref.PRIX;", cn
            
            
             taille_progressbar = taille_progressbar + 20
            UserForm1.Show
            
                    
            rs.Open "LOAD DATA LOCAL INFILE '\\\\ytkytkykty\\tkkktyytk\\16.Proxi\\Fichiers_automatisation\\prix_concurrents.csv" & _
                    "' INTO jrtjtrjtrjtrjtrjFIELDS TERMINATED BY ';' LINES TERMINATED BY '\n' IGNORE 2 LINES" & _
                    " (@dummy, @dummy, @dummy, @dummy, @dummy, @dummy, @dummy, @dummy, SIGMA, @PRIX) set PRIX= replace(@PRIX, ',','.');", cn
        
            rs.Open "Delete FROM jrtrjtrjf_exp WHERE (SIGMA = 0);", cn
            
            rs.Open "UPDATE rtjtrjtrjtj sgm INNER JOIN direction_prix_proxi.prix_crf_exp ref on sgm.SIGMA = ref.SIGMA SET sgm.prix_crf_exp = ref.PRIX;", cn
              
             
            taille_progressbar = taille_progressbar + 20
            UserForm1.Show

  • Does this answer your question? [How can I create a progress bar in Excel VBA?](https://stackoverflow.com/questions/5181164/how-can-i-create-a-progress-bar-in-excel-vba) – braX Dec 02 '21 at 10:02
  • i already saw this topic it helps me for the beginning but not for this ahaha – François Maurice Dec 02 '21 at 10:06
  • Add `DoEvents` right after you update the progress bar. VBA is single threaded, that means the running code must complete before the UI gets updated. And you don't need all those `UserForm1.Show` statements. – Kostas K. Dec 02 '21 at 10:11
  • Maybe `.repaint` at intervals in the progress? https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/repaint-method?f1url=%3FappId%3DDev11IDEF1%26l%3Den-US%26k%3Dk(fm20.chm2000380);k(TargetFrameworkMoniker-Office.Version%3Dv16)%26rd%3Dtrue – Nathan_Sav Dec 02 '21 at 10:32

0 Answers0