Interruption macros VBA sous Excel 2010

thilam

XLDnaute Junior
Bonjour à toutes et à tous,
J'ai écrit un certain nombre de macro sous Excel 2003 avant de passer à Excel 2010. Curieusement, certaines d'entre elles se bloquent au milieu de l'execution tout en donnant la possibilité de "Continuer" et se poursuivent sans problème quand je choisis cette option.
A titre d'exemple, j'en ai une qui s'arrête sur l'instruction
ActiveSheet.PageSetup.Zoom = False
Si je clique sur continuer, elle se termine sans problème
Je comprendrai que la compatibilité VBA ne soit pas totale vers Excel 2010 mais alors ça planterait carrèment, là non, c'est juste une pause. Ca n'est pas bloquant mais un tout petit peu ch...
Si quelqu'un à une solution ou au moins l'explication je suis preneur
Merci
ThL
 

thilam

XLDnaute Junior
Re : Interruption macros VBA sous Excel 2010

Bonjour C@thy et merci pour la force de réaction rapide,
A priori non, j'ai donné un exemple simplifié mais voici le code complet, pas de "On error" dans cette proc:

Sub defzonimp()
'
' Définit la zone d'impression et calibre la mise en page pour une impression sur une page

Application.ScreenUpdating = False
With ActiveSheet.PageSetup
.PrintArea = Selection.Address
.Zoom = False ' le blocage se fait ici
.LeftMargin = Application.CentimetersToPoints(1)
.RightMargin = Application.CentimetersToPoints(1)
.TopMargin = Application.CentimetersToPoints(1.5)
.BottomMargin = Application.CentimetersToPoints(1.5)
.HeaderMargin = Application.CentimetersToPoints(0.8)
.FooterMargin = Application.CentimetersToPoints(0.8)
.FitToPagesTall = 1
.FitToPagesWide = 1


If Selection.Width > Selection.Height Then
.Orientation = xlLandscape
Else
.Orientation = xlPortrait
End If
End With

Application.ScreenUpdating = True
ActiveSheet.PrintPreview
End Sub
 
Dernière édition:

thilam

XLDnaute Junior
Re : Interruption macros VBA sous Excel 2010

Un autre exemple, cette fois le blocage se fait sur le End If de l'avant dernière ligne

Sub LIGNAJ()
'
' LIGNAJ Macro
' Macro enregistrée le 23/01/02 par ThL
' complétée par une proc de Jim Rech, mpep

Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
Dim CurrCell As Range
Dim ActiveCellWidth As Single, PossNewRowHeight As Single

If ActiveCell.MergeCells = True And ActiveCell.MergeArea.Rows.Count = 1 And ActiveCell.MergeArea.WrapText = True Then
With ActiveCell.MergeArea
Application.ScreenUpdating = False
CurrentRowHeight = .RowHeight
.RowHeight = ActiveSheet.StandardHeight
ActiveCellWidth = ActiveCell.ColumnWidth
For Each CurrCell In Selection
MergedCellRgWidth = CurrCell.ColumnWidth + MergedCellRgWidth
Next
.MergeCells = False
.Cells(1).ColumnWidth = MergedCellRgWidth
.EntireRow.AutoFit
PossNewRowHeight = .RowHeight
.Cells(1).ColumnWidth = ActiveCellWidth
.MergeCells = True
.RowHeight = IIf(CurrentRowHeight > PossNewRowHeight, CurrentRowHeight, PossNewRowHeight)
Application.ScreenUpdating = True
End With

Else
Selection.Rows.AutoFit
End If ' Blocage à cet endroit
End Sub
 

Statistiques des forums

Discussions
312 499
Messages
2 088 999
Membres
104 001
dernier inscrit
dessinbecm