position d'un commentaire sur l'écran

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 !

gilles72

XLDnaute Junior
Bonjour,
j'ai le code ci-dessous qui permet qu'un objet se repositionne toujours au centre de l'écran.
Je tente de faire la même chose avec des commentaires.
en colonne A, sur 130 lignes les cellules ont chacune un commentaire.
Quand je clique sur une cellule (mettons A1), le commentaire s'affiche, mais j'aimerais qu'il se repositionne au centre de l'écran.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Shapes("Picture 113").Top = -1 + ActiveWindow.VisibleRange.Top
ActiveSheet.Shapes("Picture 113").Left = 200 + ActiveWindow.VisibleRange.Left
End Sub

J'ai tenté plusieurs modifs, sans succès.
Est-ce possible selon vous?

Et sinon, comment tester la présence d'un commentaire dans une cellule?

Merci à vous
gilles72
 
Re : position d'un commentaire sur l'écran

Bonjour,

peut être ceci :
Code:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Target
    If .Column > 1 Or .Count > 1 Then Exit Sub
    If Not .Comment Is Nothing Then
        With .Comment.Shape
            .Left = (ActiveWindow.VisibleRange.Width - .Width) / 2
            .Top = ActiveWindow.VisibleRange.Top + (ActiveWindow.VisibleRange.Height - .Height) / 2
        End With
    End If
End With
End Sub

bonne journée
@+
 
Re : position d'un commentaire sur l'écran

Re,
pour le laisserafficher après avoir bougé la souris...
Code:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static c As Comment
If Not c Is Nothing Then c.Visible = False
With Target
    If .Column > 1 Or .Count > 1 Then Exit Sub
    If Not .Comment Is Nothing Then
        Set c = .Comment
        With c
           .Visible = True
            With .Shape
                .Left = (ActiveWindow.VisibleRange.Width - .Width) / 2
                .Top = ActiveWindow.VisibleRange.Top + (ActiveWindow.VisibleRange.Height - .Height) / 2
            End With
        End With
    End If
End With
End Sub

Edition : remplacé le "With .Comment" par "with c"
 
Dernière édition:
Re : position d'un commentaire sur l'écran

Bonjour,

Code:
Dim m
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If m <> "" Then Range(m).Comment.Visible = False
    If Not Target.Comment Is Nothing Then
    Target.Comment.Visible = True
    With Target.Comment.Shape
      .Left = (ActiveWindow.VisibleRange.Width - .Width) / 2
      .Top = ActiveWindow.VisibleRange.Top + (ActiveWindow.VisibleRange.Height) / 2
    End With
    m = Target.Address
  Else
   m = ""
  End If
End Sub

http://boisgontierjacques.free.fr/pages_site/commentaire.htm#AffichePosition

JB
 

Pièces jointes

Dernière édition:
- 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

Retour