Hello,
Suis débutant VBA et j'ai un prob dans mon code. Je pensais que c'était du focus mais après essai avec le GotFocus, c'est appremment pas ca. Mais alors quoi?
En fait la procédure ci-dessous est appelée à chaque worksheet_selectionChange pour activiter/désactiver certains menus. Et quand je modifie le .enabled d'un commandButton, ben le menu déroulant de cell n'a plus "copier" activé.
Je veux dire que: je peux copier une cellule mais qd je clique droit sur une autre cellule, le menu "coller" (et "coller spécial") est désactivé. Super embetant. Je peux néanmoins coller à partir du presse-papier.
Vous avez une piste pour moi?
Merci
Michael
Sub EnableDisableStartStopCommands(ByRef rng As Range)
Dim element As Variant
Dim action As String
Dim productId As String
Dim minRow As Integer
Dim currentRow As Integer
Dim selectionStopped As Boolean
Dim oneSelectionStarted As Boolean
Dim oneAutomatonSelected As Boolean
On Error GoTo EnableDisableStartStopCommands_Error
If rng.rows.Count > 30000 Then
oneSelectionStarted = False
GoTo StartAndStopSpecified
End If
minRow = [rngBizHeaders].Row
'get the status of the selection
selectionStopped = True
oneSelectionStarted = False
oneAutomatonSelected = False
' If DictHeader Is Nothing Then
' If Not CreateColHeadersDictionary(DictHeader, Range([rngTechnicalHeaders], [rngTechnicalHeaders].End(xlToRight))) Then
' ShowError "Cannot Build Instrument Headers Dictionary" & " in procedure StartSelectedAutomatons of Module HSA_Controller"
' GoTo exitHere
' End If
' End If
' With TestMarket
' For Each element In rng.rows
' currentRow = element.Row
' action = .Cells(currentRow, CInt(DictHeader(ACTION_FIELD))).Value2
' productId = .Cells(currentRow, CInt(DictHeader(PRODUCTID_FIELD))).Value2
'
' If productId <> vbNullString And currentRow > minRow Then oneAutomatonSelected = True
' If action <> vbNullString And action <> REJECTED_ACTION Then
' selectionStopped = False
' If action <> DELETED_ACTION And action <> DISCONNECTED_ACTION Then oneSelectionStarted = True
' End If
' Next
' End With
StartAndStopSpecified:
If Not oneAutomatonSelected Then
selectionStopped = False
oneSelectionStarted = False
End If
'enable.disable start/stop command buttons
With TestMarket
.CmdStartSelectedAutomatons.Enabled = selectionStopped
.CmdStopSelectedAutomatons.Enabled = oneSelectionStarted
End With
'enable.disable start/stop on rightclick
With Application
.CommandBars("Cell").Controls(STOP_MENU_NAME).Enabled = oneSelectionStarted
.CommandBars("Cell").Controls(START_MENU_NAME).Enabled = selectionStopped
End With
'get the focus back on the selection
TestMarket.Range(rng.Address).Select
TestMarket.Activate
exitHere:
Set element = Nothing
Exit Sub
EnableDisableStartStopCommands_Error:
ShowError "Error " & Err.Number & " (" & Err.Description & ") in procedure EnableDisableStartStopCommands of Module HSA_Desktop"
Resume exitHere:
Resume
End Sub