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() Dim monImage As String Dim Sh As Shape 'Définit le nom et le lieu de stockage de l'image monImage = ActiveWorkbook.Path & "\monimage" & ".jpg" keybd_event vbKeySnapshot, 1, 0&, 0& DoEvents Range("A1").Select ActiveSheet.Paste 'on rogne l'image: à toi de régler suivant ta convenance à l'aide de l'enregistreur de macro With Selection .ShapeRange.ScaleWidth 0.68, msoFalse, msoScaleFromTopLeft .ShapeRange.ScaleHeight 0.68, msoFalse, msoScaleFromTopLeft End With 'Récupère la dernière forme de la feuille Set Sh = ActiveSheet.Shapes(ActiveSheet.Shapes.Count) 'Colle l'image dans un graphique With ActiveSheet.ChartObjects.Add(0, 0, Sh.Width, Sh.Height).Chart .Paste 'Sauvegarde l'image du graphique au format jpg .Export monImage, "JPG" End With 'Supprime le graphique et la forme. With ActiveSheet .ChartObjects(ActiveSheet.ChartObjects.Count).Delete .Shapes(ActiveSheet.Shapes.Count).Delete End With Application.ScreenUpdating = True MsgBox "L'image est sauvegardée dans le dossier du classeur." End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub CommandButton1_Click() k = 0.7 Me.Width = Me.Width * k Me.Height = Me.Height * k Me.Zoom = k * 100 End Sub
Public Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Const GWL_STYLE = (-16) Const WS_CAPTION = &HC00000 Const SWP_FRAMECHANGED = &H20 Public Declare Function FindWindowA Lib "User32" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Declare Function GetWindowRect Lib "User32" _ (ByVal hWnd As Long, lpRect As RECT) As Long Public Declare Function GetWindowLong Lib "User32" Alias _ "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long Public Declare Function SetWindowLong Lib "User32" Alias _ "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, _ ByVal dwNewLong As Long) As Long Public Declare Function SetWindowPos Lib "User32" _ (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, _ ByVal y As Long, ByVal cx As Long, ByVal cy As Long, _ ByVal wFlags As Long) As Long Sub AfficheTitleBarre(stCaption As String, pbVisible As Boolean) Dim vrWin As RECT Dim style As Long Dim lHwnd As Long '- Recherche du handle de la fenêtre par son Caption lHwnd = FindWindowA(vbNullString, stCaption) If lHwnd = 0 Then MsgBox "Handle de " & stCaption & " Introuvable", vbCritical Exit Sub End If GetWindowRect lHwnd, vrWin style = GetWindowLong(lHwnd, GWL_STYLE) If pbVisible Then SetWindowLong lHwnd, GWL_STYLE, style Or WS_CAPTION Else SetWindowLong lHwnd, GWL_STYLE, style And Not WS_CAPTION End If SetWindowPos lHwnd, 0, vrWin.Left, vrWin.Top, vrWin.Right - vrWin.Left, _ vrWin.Bottom - vrWin.Top, SWP_FRAMECHANGED End Sub
Private Sub CommandButton3_Click() 'On passe en arguments : ' - le titre de la fenêtre ' - False pour masquer la barre de titre AfficheTitleBarre Me.Caption, False End Sub Private Sub CommandButton4_Click() 'On passe en arguments : ' - le titre de la fenêtre ' - True pour afficher la barre de titre AfficheTitleBarre Me.Caption, True End Sub
With Selection .ShapeRange.PictureFormat.CropLeft = 13.5 .ShapeRange.PictureFormat.CropTop = 34.5 .ShapeRange.PictureFormat.CropBottom = 24# .ShapeRange.PictureFormat.CropRight = 299.25 End With
Private Sub CommandButton1_Click() Dim monImage As String Dim Sh As Shape 'Définit le nom et le lieu de stockage de l'image monImage = ActiveWorkbook.Path & "\monimage" & ".jpg" keybd_event vbKeySnapshot, 1, 0&, 0& DoEvents Range("A1").Select ActiveSheet.Paste 'on rogne l'image: à toi de régler suivant ta convenance à l'aide de l'enregistreur de macro With Selection .ShapeRange.PictureFormat.CropLeft = 13.5 .ShapeRange.PictureFormat.CropTop = 34.5 .ShapeRange.PictureFormat.CropBottom = 24# .ShapeRange.PictureFormat.CropRight = 299.25 End With 'Récupère la dernière forme de la feuille Set Sh = ActiveSheet.Shapes(ActiveSheet.Shapes.Count) 'Colle l'image dans un graphique With ActiveSheet.ChartObjects.Add(0, 0, Sh.Width, Sh.Height).Chart .Paste 'Sauvegarde l'image du graphique au format jpg .Export monImage, "JPG" End With 'Supprime le graphique et la forme. With ActiveSheet .ChartObjects(ActiveSheet.ChartObjects.Count).Delete .Shapes(ActiveSheet.Shapes.Count).Delete End With Application.ScreenUpdating = True MsgBox "L'image est sauvegardée dans le dossier du classeur." AfficheTitleBarre Me.Caption, True ' rétablir la barre de titre End Sub Private Sub UserForm_Initialize() AfficheTitleBarre Me.Caption, False 'masquer la barre de titre End Sub