XL 2010 Redimensionner une image

Magic_Doctor

XLDnaute Barbatruc
Bonjour,

Le problème est le suivant :
Je clique sur un bouton et apparaissent :
- une image qui occupe une partie de l'écran
- un bouton qui, lorsque je clique dessus, commande le redimensionnement de l'image afin qu'elle occupe pratiquement tout l'écran. Si je reclique sur ce bouton, l'image reprend ses dimensions antérieures.
Je ne parviens pas à redimensionner cette image. J'ai bien essayé avec l'enregistreur de macro mais sans succès.
Comment s'y prendre ?
 

job75

XLDnaute Barbatruc
Bonjour Magic_Doctor, le forum,

Vois si ceci te convient :
VB:
Sub Image()
Dim test As Boolean
With ThisWorkbook.Names
    .Add "X", 190
    .Add "Y", 80
    .Add "W", 260
    .Add "H", 120
End With
With ActiveSheet.DrawingObjects("Bouton")
    test = .Text = "Grand"
    .Text = IIf(test, "Petit", "Grand")
End With
Application.DisplayFullScreen = test
With ActiveSheet.Shapes("Mon_Image")
    .Left = IIf(test, 0, [X])
    .Top = IIf(test, 0, [Y])
    .Width = IIf(test, Application.Width, [W])
    .Height = IIf(test, Application.Height, [H])
End With
End Sub
Bonne journée.
 

Pièces jointes

  • Mon_Image(1).xlsm
    19.3 KB · Affichages: 26

patricktoulon

XLDnaute Barbatruc
bonsoir @job75
on peut simplifier
VB:
Option Explicit

Sub Image()
    With ActiveSheet.Shapes("Mon_Image")
        Application.DisplayFullScreen = .Width = 260
        .Left = IIf(.Left = 190, 0, 190)
        .Top = IIf(.Top = 80, 0, 80)
        .Width = IIf(.Width = 260, Application.Width, 260)
        .Height = IIf(.Height = 120, Application.Height, 120)
    End With
End Sub
 

job75

XLDnaute Barbatruc
Bonsoir patricktoulon,

Je préfère cette amélioration qui mémorise les dernières position et dimensions, fichier (2) :
VB:
Sub Image()
Dim test As Boolean, im As Shape
With ActiveSheet.DrawingObjects("Bouton")
    test = .Text = "Grande"
    .Text = IIf(test, "Petite", "Grande")
End With
Set im = ActiveSheet.Shapes("Mon_Image")
If test Then
    With ThisWorkbook.Names
        .Add "X", im.Left 'mémorise la dernière position
        .Add "Y", im.Top
        .Add "W", im.Width 'mémorise les dernières dimensions
        .Add "H", im.Height
    End With
End If
Application.DisplayFullScreen = test
With im
    .Left = IIf(test, 0, [X])
    .Top = IIf(test, 0, [Y])
    .Width = IIf(test, Application.Width, [W])
    .Height = IIf(test, Application.Height, [H])
End With
End Sub
A+
 

Pièces jointes

  • Mon_Image(2).xlsm
    20.4 KB · Affichages: 9

Discussions similaires

Statistiques des forums

Discussions
312 242
Messages
2 086 532
Membres
103 243
dernier inscrit
SAH