Option Explicit
Private Declare Sub keybd_event Lib "user32" ( _
ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
Sub Masquer_Afficher_Ruban()
'Simule Ctrl+F1 (à lancer depuis la feuille de calcul)
Const VK_CONTROL = &H11
Const VK_F1 = &H70
Const KEYEVENTF_KEYUP = &H2
keybd_event VK_CONTROL, 0, 0, 0
keybd_event VK_F1, 0, 0, 0
keybd_event VK_F1, 0, KEYEVENTF_KEYUP, 0
keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0
End Sub
Option Explicit
Private Declare Sub keybd_event Lib "user32" ( _
ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
Private Sub CommandButton1_Click()
'Simule Ctrl+F1 (à lancer depuis la feuille de calcul)
Const VK_CONTROL = &H11
Const VK_F1 = &H70
Const KEYEVENTF_KEYUP = &H2
Range("A1").Select
DoEvents
keybd_event VK_CONTROL, 0, 0, 0
keybd_event VK_F1, 0, 0, 0
keybd_event VK_F1, 0, KEYEVENTF_KEYUP, 0
keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0
End Sub
Je n'utilise jamais les SendKeys car ça ne fonctionne pas une fois sur deux. personnellement je n'ai jamais réussi à les faire fonctionner de façon fiable.Mais si je puis me permettre, pour simuler une touche il y a plus simple:
Application.SendKeys "^{F1}" suffit et c'est tout de même plus court.
Tu peux stocker l'information dans un endroit de ton choix qui indiquera si ta fonction BarOutilsVisible doit etre masquée/affichée:Faudrait pouvoir détecter si le Ruban est Afficher ou Masquer comprends tu !?
pour ne pas effectuer Ctrl+F1 qui réafficherai alors qu'il ne le faut pas.