Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

macro se repetant deux fois !!

2 réponses
Avatar
david
Bonjour
Je veux executer une macro à partir d'un click droit sur une cellule , cette
macro s'execute deux foix lorsqu'il y a un argument.Comment eviter celà
Merci de votre aide (ci joint le code)
'au niveau de la feuille

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Application.ScreenUpdating = False 'au hasard
Application.EnableEvents = False 'au hasard
If Target.Address = "$A$1" Then 'selection cellule A1
Dim X, N As Integer
X = Application.CommandBars("Cell").Controls.Count
For N = 1 To X
Application.CommandBars("Cell").Controls(1).Delete
Next N
With Application.CommandBars("Cell").Controls.Add
.Caption = "TEST" 'Intitulé du menu
.OnAction = ThisWorkbook.Name & "!test(3)" 'Message est le nom de la
macro à lancer
End With
Else
Application.CommandBars("Cell").Reset
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

et dans un module

Sub test(lenombre As Integer)
MsgBox lenombre
End Sub

2 réponses

Avatar
papou
Bonjour
Et pourquoi pas un simple :
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$1" Then test (3)
End Sub

Cordialement
Pascal

"david" a écrit dans le message de
news:4045ca4c$0$5916$
Bonjour
Je veux executer une macro à partir d'un click droit sur une cellule ,
cette

macro s'execute deux foix lorsqu'il y a un argument.Comment eviter celà
Merci de votre aide (ci joint le code)
'au niveau de la feuille

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Application.ScreenUpdating = False 'au hasard
Application.EnableEvents = False 'au hasard
If Target.Address = "$A$1" Then 'selection cellule A1
Dim X, N As Integer
X = Application.CommandBars("Cell").Controls.Count
For N = 1 To X
Application.CommandBars("Cell").Controls(1).Delete
Next N
With Application.CommandBars("Cell").Controls.Add
.Caption = "TEST" 'Intitulé du menu
.OnAction = ThisWorkbook.Name & "!test(3)" 'Message est le nom de la
macro à lancer
End With
Else
Application.CommandBars("Cell").Reset
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

et dans un module

Sub test(lenombre As Integer)
MsgBox lenombre
End Sub




Avatar
david
Il faut avoir le choix d'executer la macro avec le click droit
Merci
"papou" <DesolePasDeMail> a écrit dans le message de
news:%
Bonjour
Et pourquoi pas un simple :
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$1" Then test (3)
End Sub

Cordialement
Pascal

"david" a écrit dans le message de
news:4045ca4c$0$5916$
Bonjour
Je veux executer une macro à partir d'un click droit sur une cellule ,
cette

macro s'execute deux foix lorsqu'il y a un argument.Comment eviter celà
Merci de votre aide (ci joint le code)
'au niveau de la feuille

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Application.ScreenUpdating = False 'au hasard
Application.EnableEvents = False 'au hasard
If Target.Address = "$A$1" Then 'selection cellule A1
Dim X, N As Integer
X = Application.CommandBars("Cell").Controls.Count
For N = 1 To X
Application.CommandBars("Cell").Controls(1).Delete
Next N
With Application.CommandBars("Cell").Controls.Add
.Caption = "TEST" 'Intitulé du menu
.OnAction = ThisWorkbook.Name & "!test(3)" 'Message est le nom de
la


macro à lancer
End With
Else
Application.CommandBars("Cell").Reset
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

et dans un module

Sub test(lenombre As Integer)
MsgBox lenombre
End Sub