Recalculer après un changement de format

Je cherche à faire recalculer une fonction dès qu'une cellule est mise en gras

Application.volatile permet de recalculer lorsqu'une cellule a été modifiée dans sa valeur mais pas dans son format. Tu peux cependant intercepter l'action du bouton qui met en gras. La macro intercept_gras" détecte l'action et lance la macro "trouvé" qui elle, met du gras ou l'enlève et recalcule. Lla 3ème macro sert à réinitialiser l'action normale de la mise en gras.

sub intercept_gras()
  Dim Ctl As CommandBarControl
  For Each Ctl In Application.CommandBars("Formatting").Controls
    If Ctl.Caption = "&Gras" Then
      Ctl.OnAction = "trouvé"
    End If
  Next Ctl
 end sub
sub trouvé()
  If Selection.Font.Bold = True Then
    Selection.Font.Bold = False
  Else
    Selection.Font.Bold = True
  End If
  Calculate
 end sub
sub reinit_Gras()
  Dim Ctl As CommandBarControl
  For Each Ctl In Application.CommandBars("Formatting").Controls
    If Ctl.Caption = "&Gras" Then
      Ctl.OnAction = ""
    End If
  Next Ctl
 end sub

Auteur :

Mots clefs associés à cette page : , ,