rendre ma macro plus rapide

  • Initiateur de la discussion Initiateur de la discussion fenec
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

fenec

XLDnaute Impliqué
Bonjour le forum
Venant grâce à l’enregistreur de rajouter la mise en page (en bleu) de ma sauvegarde je m’adresse à vous pour savoir s’il serait possible de la réduire afin de la rendre plus rapide
D’avance merci
Cordialement
Fenec


Private Sub CommandButton10_Click() 'Archiver Bon de Commande avec N° incrémenter
Application.ScreenUpdating = False
NomFichier = ActiveWorkbook.Name
défaut = Application.SheetsInNewWorkbook
Application.SheetsInNewWorkbook = 1
Workbooks.Add
Application.SheetsInNewWorkbook = défaut
nomfichier1 = ActiveWorkbook.Name
Me.Cells.Copy ActiveSheet.[A1]
ActiveSheet.Cells.Clear
With Me.Range("Zone_d_impression")
.Copy ActiveSheet.[B2]
ActiveSheet.[B2].Resize(.Rows.Count, .Columns.Count).Locked = True

With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = "$B$2:$J$58"
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = "Page &P de &N"
.LeftFooter = ""
.CenterFooter = _
"S.A.R.L au capital "
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0)
.RightMargin = Application.InchesToPoints(0)
.TopMargin = Application.InchesToPoints(0.393700787401575)
.BottomMargin = Application.InchesToPoints(0)
.HeaderMargin = Application.InchesToPoints(0)
.FooterMargin = Application.InchesToPoints(0.196850393700787)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.CenterHorizontally = True
.CenterVertically = False
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 59
.PrintErrors = xlPrintErrorsDisplayed

End With
ActiveSheet.Protect
ActiveSheet.Range("B6").Select
ChDir "C:\Users\Philippe\Documents\Archives\bon de commande"
'fermer = Application.GetSaveAsFilename(ActiveSheet.Range("E13").Value & Format(Now, " dd-mm-yyyy ""à"" hh""h""mm""mn""ss""s"), "Fichiers Excel,*.xls")
fermer = Application.GetSaveAsFilename(ActiveSheet.Range("E13").Value & " " & Range("I14"), "Fichiers Excel,*.xls")
If fermer = False Then
Windows(nomfichier1).Activate
ActiveWorkbook.Close savechanges:=False
Exit Sub
End If
ActiveWorkbook.SaveAs Filename:=fermer
ActiveWorkbook.Close
NonClient = Range("E13")
num = Format(Val(Right(Range("I14"), 3)) + 1, "000")
ActiveSheet.Unprotect
Range("L2") = num
Workbooks("exemple.1.xls").Activate
Range("Zone_a_remplir") = Empty
Range("E13").Select
ActiveWorkbook.Save
Application.ScreenUpdating = True

End With

End Sub
 
Re : rendre ma macro plus rapide

Salut Fenec, le fil,

Tu peux enlever les lignes inutiles, mais tu ne gagneras presque rien en temps d'éxécution!

Lignes inutiles = lignes contenant des valeurs par défaut comme par exemple :
.LeftHeader = ""
.CenterHeader = ""
.LeftFooter = ""
.RightFooter = ""
.CenterVertically = False

Bonne après midi
 
Re : rendre ma macro plus rapide

Hello,

Rien de pire que de balancer le code comme ça, mieux vaut joindre un fichier sans données confidentielles !

Sans conviction donc, essaie ceci...
Code:
Private Sub CommandButton10_Click() 'Archiver Bon de Commande avec N° incrémenter
Application.ScreenUpdating = False
NomFichier = ActiveWorkbook.Name
défaut = Application.SheetsInNewWorkbook
Application.SheetsInNewWorkbook = 1
Workbooks.Add
Application.SheetsInNewWorkbook = défaut
nomfichier1 = ActiveWorkbook.Name
Me.Cells.Copy ActiveSheet.[A1]
ActiveSheet.Cells.Clear
With Me.Range("Zone_d_impression")
.Copy ActiveSheet.[B2]
ActiveSheet.[B2].Resize(.Rows.Count, .Columns.Count).Locked = True

'=============================================
ActiveSheet.PageSetup.PrintArea = "$B$2:$J$58"
With ActiveSheet.PageSetup
.RightHeader = "Page &P de &N"
.CenterFooter = "S.A.R.L au capital "
.Orientation = xlPortrait
.Zoom = 59 '<- Pas sûr que besoin
End With
'=============================================

ActiveSheet.Protect
ActiveSheet.Range("B6").Select
ChDir "C:\Users\Philippe\Documents\Archives\bon de commande"
'fermer = Application.GetSaveAsFilename(ActiveSheet.Range("E 13").Value & Format(Now, " dd-mm-yyyy ""à"" hh""h""mm""mn""ss""s"), "Fichiers Excel,*.xls")
fermer = Application.GetSaveAsFilename(ActiveSheet.Range("E 13").Value & " " & Range("I14"), "Fichiers Excel,*.xls")
If fermer = False Then
Windows(nomfichier1).Activate
ActiveWorkbook.Close savechanges:=False
Exit Sub
End If
ActiveWorkbook.SaveAs Filename:=fermer
ActiveWorkbook.Close
NonClient = Range("E13")
num = Format(Val(Right(Range("I14"), 3)) + 1, "000")
ActiveSheet.Unprotect
Range("L2") = num
Workbooks("exemple.1.xls").Activate
Range("Zone_a_remplir") = Empty
Range("E13").Select
ActiveWorkbook.Save
Application.ScreenUpdating = True

End With

End Sub
EDIT : Slt MJ, Excel-lent 🙂

Comme le dit Excel-lent, tu ne gagnera pas grand chose en vitesse...
 
Dernière édition:
Re : rendre ma macro plus rapide

Bonsoir à tous,

c'est juste une idée, ceci est le code donné par Fréderic Sigonneau pour rendre l'éxecution d'une macro plus rapide.

Code:
'accélerer le code en désactivant en début de procédure puis
'réactivant en fin de procédure les options d'Excel qui
'ralentissent l'exécution.
'Ex
'  Sub MaProc()
'    FastRun False
'    'code
'    FastRun True
'  End Sub

Function FastRun(Setting)
'Peter Fossey, mpep

  Application.StatusBar = "Updating Excel settings, please wait..."
  Application.EnableCancelKey = xlDisabled
  Application.ScreenUpdating = Setting
  Application.DisplayAlerts = Setting
  Application.Interactive = Setting
  If Setting = False Then Application.Calculation = xlCalculationManual
  If Setting = False Then Application.Cursor = xlWait
  If Setting = True Then Application.Calculation = xlCalculationAutomatic
  If Setting = True Then Application.Cursor = xlDefault
  Application.StatusBar = False
  
End Function

A tester.


A+ 😎
 
Re : rendre ma macro plus rapide

Bonsoir Excel-lent,

bon d'accord, l'auteur original est Peter Fossey, et pour le code lui même je ne peut rien dire au juste dit quoi il en retourne.

Quelques explications (sur le code) seraient les bienvenues. 😉


Bonne soirée 😎
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
2
Affichages
2 K
Réponses
17
Affichages
2 K
Réponses
0
Affichages
1 K
Retour