Bonjour,
Sauf erreur de ma part, on ne peut changer directement l'angle dans un userform. Il faut passer par une étape intermédiaire consistant à changer l'angle dans la forme présente dans un onglet, en capturer l'image et l'importer dans le userform.
Dans le fichier joint, les touches A et Z augmentent ou diminuent l'angle du bouton dans le userform.
Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = vbKeyA Then
AugmenterLAngle
Apercu_Dans_Uf
End If
If KeyCode = vbKeyZ Then
DiminuerLAngle
Apercu_Dans_Uf
End If
End Sub
Le code Apercu_Dans_Uf du module 2 n'est pas de moi :
Option Explicit
Public Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(8) As Byte
End Type
Public Type PICTDESC
cbSize As Long
picType As Long
hImage As Long
End Type
Public Declare Function OpenClipboard& Lib "user32" (ByVal hwnd As Long)
Public Declare Function EmptyClipboard Lib "user32" () As Long
Public Declare Function GetClipboardData& Lib "user32" (ByVal wFormat%)
Public Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Public Declare Function CloseClipboard& Lib "user32" ()
Public Declare Function CopyImage& Lib "user32" (ByVal handle&, ByVal un1&, ByVal n1&, ByVal n2&, ByVal un2&)
Public Declare Function IIDFromString Lib "ole32" (ByVal lpsz As String, ByRef lpiid As GUID) As Long
Public Declare Function OleCreatePictureIndirect Lib "olepro32" (pPictDesc As PICTDESC, ByRef riid As GUID, ByVal fOwn As Long, ByRef ppvObj As IPicture) As Long
Public mode As Long
Sub VidePP()
OpenClipboard 0
EmptyClipboard
CloseClipboard
End Sub
Sub Apercu_Dans_Uf()
Dim NOM_IMAGE As Variant
'On copie la selection dans le clipboard
Sheets("Feuil1").Shapes("Bouton").CopyPicture xlScreen, xlBitmap 'Copie la selection dans le clipboard
'Prend l'image dans le cliboard
Dim hCopy&: OpenClipboard 0&
hCopy = CopyImage(GetClipboardData(2), 0, 0, 0, &H8)
CloseClipboard
If hCopy = 0 Then Exit Sub
Const IPictureIID = "{7BF80981-BF32-101A-8BBB-00AA00300CAB}"
Dim iPic As IPicture, tIID As GUID, tPICTDEST As PICTDESC, Ret As Long
Ret = IIDFromString(StrConv(IPictureIID, vbUnicode), tIID)
If Ret Then Exit Sub
With tPICTDEST
.cbSize = Len(tPICTDEST)
.picType = 1
.hImage = hCopy
End With
Ret = OleCreatePictureIndirect(tPICTDEST, tIID, 1, iPic)
If Ret Then Exit Sub
UserForm1.Image1.Picture = iPic
Set iPic = Nothing
VidePP
End Sub
Option Explicit
Sub ImporterPhoto()
Dim Sh As Shape
Dim Img As PictureFormat
Set Sh = Worksheets("Feuil1").Shapes("Bouton")
With UserForm1
Apercu_Dans_Uf
.Show
End With
End Sub
Sub AugmenterLAngle()
With Sheets("Feuil1")
.Shapes("Bouton").IncrementRotation 10
End With
End Sub
Sub DiminuerLAngle()
With Sheets("Feuil1")
.Shapes("Bouton").IncrementRotation -10
End With
End Sub