XL 2010 Afficher du texte clic image avec classeur verrouillé

Orson83

XLDnaute Impliqué
Bonjour à toutes et tous,
J'ai une macro qui permet d'afficher un texte en cliquant sur une image. Je ne parviens pas à afficher ce texte quand mon classeur est verrouillé. Serait-il possible que le texte puisse s'afficher quand le classeur est verrouillé ? (formules et VBA protégés).
PS : il y a une condition dans la macro qui interdit de renommer l'onglet, à priori, cette condition ne devrait pas générer de conflit dans cette macro.
Le fichier exemple se trouve dans ce post. Merci pour votre aide.
Tchotchodu31
 

Pièces jointes

  • Afficher-du-texte-classeur-verrouillé.xlsm
    58 KB · Affichages: 7
Solution
A essayer :
VB:
'AFFICHE LE TEXTE "INFO" EN CLIQUANT SUR L'IMAGE ET RETABLIT LE NOM DE L'ONGLET AU CLIC DANS LA PAGE
Const MDP = "****"  '<--- Mot de passe à renseigner
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Protected = ActiveSheet.ProtectContents
    If Not Target.Address = Range("d4").MergeArea.Address Then
        If Protected Then ActiveSheet.Unprotect MDP
            Range("d4").NumberFormat = ";;;"
        If Protected Then ActiveSheet.Protect MDP
    End If
    If ActiveSheet.Name <> "Rapport" Then
        ActiveSheet.Name = "Rapport"
    End If
End Sub

Sub afficheTxt()
Dim Protected As Boolean
Protected = ActiveSheet.ProtectContents

    'Macro à affecter à l'image avec le clic droit
    If Protected Then...

fanch55

XLDnaute Barbatruc
Salut,
Il faudrait fournir un fichier où le verrouillage ne soit pas protégé par mot de passe.
On pourrait le forcer, certes car rien n'est véritablement sécurisé dans Excel mais ce serait contraire à toute déontologie ...

Ouups, en regardant le code, je vois que le mdp est indiqué , je n'avais pas vu ...:rolleyes:
 

fanch55

XLDnaute Barbatruc
VB:
'AFFICHE LE TEXTE "INFO" EN CLIQUANT SUR L'IMAGE ET RETABLIT LE NOM DE L'ONGLET AU CLIC DANS LA PAGE
Const MDP = "****"  ''<--- Mot de passe à renseigner
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Not Target.Address = Range("d4").MergeArea.Address Then
        ActiveSheet.Unprotect MDP
            Range("d4").NumberFormat = ";;;"
        ActiveSheet.Protect MDP
    End If
    
    If ActiveSheet.Name <> "Rapport" Then
        ActiveSheet.Name = "Rapport"
    End If
End Sub

Sub afficheTxt()
   'Macro à affecter à l'image avec le clic droit
    ActiveSheet.Unprotect MDP
        Range("d4").NumberFormat = "General"
    ActiveSheet.Protect MDP

End Sub
 

Orson83

XLDnaute Impliqué
VB:
'AFFICHE LE TEXTE "INFO" EN CLIQUANT SUR L'IMAGE ET RETABLIT LE NOM DE L'ONGLET AU CLIC DANS LA PAGE
Const MDP = "****"  ''<--- Mot de passe à renseigner
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Not Target.Address = Range("d4").MergeArea.Address Then
        ActiveSheet.Unprotect MDP
            Range("d4").NumberFormat = ";;;"
        ActiveSheet.Protect MDP
    End If
   
    If ActiveSheet.Name <> "Rapport" Then
        ActiveSheet.Name = "Rapport"
    End If
End Sub

Sub afficheTxt()
   'Macro à affecter à l'image avec le clic droit
    ActiveSheet.Unprotect MDP
        Range("d4").NumberFormat = "General"
    ActiveSheet.Protect MDP

End Sub

Bonsoir fanch55,
Merci pour cette macro qui permet effectivement d'afficher le texte en mode verrouillé.
J'ai juste un petit problème de déverrouillage.
Quand je déverrouille mon classeur depuis le bouton qui se trouve dans la page "Accueil", toutes les pages se déverrouillent sauf la page "Rapport" qui contient le code.
Je peux déverrouiller depuis "Révision" mais le verrouillage est automatique quand je clique dans une cellule.
Penses-tu que cela pourrait venir du code d'affichage du texte qui efface le texte en sortie de cellule D4 ??
Exemple en PJ.
Tchotchodu31
 

Pièces jointes

  • Afficher-du-texte-classeur-verrouillé-V2.xlsm
    61.4 KB · Affichages: 9

fanch55

XLDnaute Barbatruc
A essayer :
VB:
'AFFICHE LE TEXTE "INFO" EN CLIQUANT SUR L'IMAGE ET RETABLIT LE NOM DE L'ONGLET AU CLIC DANS LA PAGE
Const MDP = "****"  '<--- Mot de passe à renseigner
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Protected = ActiveSheet.ProtectContents
    If Not Target.Address = Range("d4").MergeArea.Address Then
        If Protected Then ActiveSheet.Unprotect MDP
            Range("d4").NumberFormat = ";;;"
        If Protected Then ActiveSheet.Protect MDP
    End If
    If ActiveSheet.Name <> "Rapport" Then
        ActiveSheet.Name = "Rapport"
    End If
End Sub

Sub afficheTxt()
Dim Protected As Boolean
Protected = ActiveSheet.ProtectContents

    'Macro à affecter à l'image avec le clic droit
    If Protected Then ActiveSheet.Unprotect MDP
        Range("d4").NumberFormat = "General"
    If Protected Then ActiveSheet.Protect MDP
End Sub
 

Orson83

XLDnaute Impliqué
A essayer :
VB:
'AFFICHE LE TEXTE "INFO" EN CLIQUANT SUR L'IMAGE ET RETABLIT LE NOM DE L'ONGLET AU CLIC DANS LA PAGE
Const MDP = "****"  '<--- Mot de passe à renseigner
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Protected = ActiveSheet.ProtectContents
    If Not Target.Address = Range("d4").MergeArea.Address Then
        If Protected Then ActiveSheet.Unprotect MDP
            Range("d4").NumberFormat = ";;;"
        If Protected Then ActiveSheet.Protect MDP
    End If
    If ActiveSheet.Name <> "Rapport" Then
        ActiveSheet.Name = "Rapport"
    End If
End Sub

Sub afficheTxt()
Dim Protected As Boolean
Protected = ActiveSheet.ProtectContents

    'Macro à affecter à l'image avec le clic droit
    If Protected Then ActiveSheet.Unprotect MDP
        Range("d4").NumberFormat = "General"
    If Protected Then ActiveSheet.Protect MDP
End Sub

Super ! le code fonctionne parfaitement.
Un grand merci pour cette intervention ;)
Très bonne soirée.
A bientôt.
Tchotchodu31
 

Discussions similaires

Statistiques des forums

Discussions
312 182
Messages
2 086 004
Membres
103 085
dernier inscrit
ACHIKLLLE