Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim OL As OLEObject
Private Sub ListBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
Dim i&
Dim j&
Dim L As msforms.Label
On Error GoTo Erreur
If Button = 2 Then
For i& = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i&) = True Then
Application.ScreenUpdating = False
Set OL = ActiveSheet.OLEObjects.Add(ClassType:="Forms.Label.1", Link:=False, _
DisplayAsIcon:=False, Left:=Me.Left - 20, Top:=10, Width:=500, Height:=100)
Set L = OL.Object
L.TextAlign = fmTextAlignLeft
L.Caption = ListBox1.Value
L.Font.Underline = False
L.AutoSize = True
L.BackColor = RGB(255, 255, 190)
Application.ScreenUpdating = True
Exit For
End If
Next i&
End If
Erreur:
If Err <> 0 Then MsgBox "coucou"
End Sub
Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
If Button = 2 Then
If Not OL Is Nothing Then
Sleep 500
OL.Cut
Set OL = Nothing
End If
End If
End Sub
Private Sub UserForm_Initialize()
Dim var
var = Sheets("test").UsedRange
With ListBox1
.List = var
End With
End Sub