Bonjour,

J'ai une macro au travail pour insérer des images et compresser a la suite sur des case fusionnées

En faite quand la photo est en horizontale tout va bien, par contre quand j’insère une photo verticale elle me fait une rotation de 90°

Je ne vois pas où ça fait une rotation dans la macro, pouvez-vous m'aider ?

Merci

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
Sub compress()
Dim Sh As Shape
Dim octl As CommandBarControl
Set octl = Application.CommandBars.FindControl(ID:=6382)
Application.SendKeys "%(oe)~{TAB}~"
 
    Application.CommandBars.ExecuteMso "PicturesCompress"
End Sub
 
 
 
Sub INSERTION_PHOTO()
'Insertion avec un ration
 
 
Dim strImage As String
Dim Sh As Shape
 
Dim ficimg As String, Ad As String
Dim MemW As Long, MemH As Long, T As Integer, L As Integer
Dim Lg As Integer, HT As Integer, RatioCell As Single
Dim CellH As Long, CellW As Long, RatioHz As Single, RatioVt As Single
Ad = SELECTION.Address
    CellH = SELECTION.Height
    CellW = SELECTION.Width
 
 
 
ficimg = Application.GetOpenFilename(".jpg,*.jpg", , "Choisissez l'image") ' choix nom du fichier
    If ficimg = "Faux" Then Exit Sub
 
'Dimension de la Photo
 
L = 3264
H = 2248
 
 
'Set Sh = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 300, 200, 167, 130)
Set Sh = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 300, 200, L, H)
With Sh
    .Select
    SELECTION.ShapeRange.Line.Visible = msoFalse
    SELECTION.ShapeRange.Shadow.Visible = msoFalse
    SELECTION.ShapeRange.AlternativeText = ficimg
     MemW = .Width: MemH = .Height
        'adapte les ratio
        If MemH < CellH And MemW < CellW Then
        'l'image < cellule
            RatioHz = MemH / CellH
            RatioVt = MemW / CellW
            If RatioVt < RatioHz Then 'adapter en hauteur
                HT = CellH:  Lg = MemW * (HT / MemH)
                T = 0: L = (CellW - Lg) / 2
            Else 'adapter en largeur
                Lg = CellW: HT = MemH * (CellW / MemW)
                L = 0: T = (CellH - HT) / 2
            End If
        ElseIf MemH > CellH And MemW > CellW Then
        'l'image > cellule
            RatioHz = CellH / MemH
            RatioVt = CellW / MemW
            If RatioVt > RatioHz Then 'adapter en hauteur
                HT = CellH:  Lg = MemW * (HT / MemH)
                T = 0: L = (CellW - Lg) / 2
            Else 'adapter en largeur
                Lg = CellW: HT = MemH * (Lg / MemW)
                L = 0: T = (CellH - HT) / 2
            End If
        ElseIf MemH > CellH And MemW < CellW Then
        'adapter en hauteur
            HT = CellH:  Lg = MemW * (HT / MemH)
            T = 0: L = (CellW - Lg) / 2
        ElseIf MemH < CellH And MemW > CellW Then
        'adapter en largeur
            Lg = CellW: HT = MemH * (Lg / MemW)
            L = 0: T = (CellH - HT) / 2
        Else
            Stop ' pas prévu ?
        End If
 
        .LockAspectRatio = False ' proportions d'origine lorsque vous la redimensionnez
        .Top = Range(Ad).Top + T + 2 ' haut de la cellule
        .Left = Range(Ad).Left + L + 2 ' gauche de la cellule
        .Height = HT - 4
        .Width = Lg - 4 ' largeur des cellules fusionnées
End With
 
Sh.Fill.UserPicture ficimg
 
'With ficimg.Select
 
'    SELECTION.ShapeRange.Height = 141.7322834646
'    SELECTION.ShapeRange.Fill.Visible = msoFalse
'    SELECTION.ShapeRange.Line.Visible = msoFalse
'End With
Call compress
ActiveCell.Offset(0, 1).Select
End Sub
 
Sub SUPPRESSION_PHOTOS()
Dim S As Shape
For Each S In ActiveSheet.Shapes
If TypeName(S.OLEFormat.Object) = "Rectangle" Then
S.Delete
End If
Next
 
For Each S In ActiveSheet.Shapes
If TypeName(S.OLEFormat.Object) = "Picture" Then
S.Delete
End If
Next
 
End Sub
 
Sub PHOTO_FORMAT_CASE()
 
Dim strImage As String
Dim Sh As Shape
 
Dim ficimg As String, Ad As String
Dim MemW As Long, MemH As Long, T As Integer, L As Integer
Dim Lg As Integer, HT As Integer, RatioCell As Single
Dim CellH As Long, CellW As Long, RatioHz As Single, RatioVt As Single
Ad = SELECTION.Address
    CellH = SELECTION.Height
    CellW = SELECTION.Width
 
 
 
ficimg = Application.GetOpenFilename(".jpg,*.jpg", , "Choisissez l'image") ' choix nom du fichier
    If ficimg = "Faux" Then Exit Sub
 
 
Set Sh = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 300, 200, 167, 130)
 
With Sh
    .Select
    SELECTION.ShapeRange.Line.Visible = msoFalse
    SELECTION.ShapeRange.Shadow.Visible = msoFalse
    SELECTION.ShapeRange.AlternativeText = ficimg
     MemW = .Width: MemH = .Height
        'adapte les ratio
        If MemH < CellH And MemW < CellW Then
        'l'image < cellule
            RatioHz = MemH / CellH
            RatioVt = MemW / CellW
            If RatioVt < RatioHz Then 'adapter en hauteur
                HT = CellH:  Lg = MemW * (HT / MemH)
                T = 0: L = (CellW - Lg) / 2
            Else 'adapter en largeur
                Lg = CellW: HT = MemH * (CellW / MemW)
                L = 0: T = (CellH - HT) / 2
            End If
        ElseIf MemH > CellH And MemW > CellW Then
        'l'image > cellule
            RatioHz = CellH / MemH
            RatioVt = CellW / MemW
            If RatioVt > RatioHz Then 'adapter en hauteur
                HT = CellH:  Lg = MemW * (HT / MemH)
                T = 0: L = (CellW - Lg) / 2
            Else 'adapter en largeur
                Lg = CellW: HT = MemH * (Lg / MemW)
                L = 0: T = (CellH - HT) / 2
            End If
        ElseIf MemH > CellH And MemW < CellW Then
        'adapter en hauteur
            HT = CellH:  Lg = MemW * (HT / MemH)
            T = 0: L = (CellW - Lg) / 2
        ElseIf MemH < CellH And MemW > CellW Then
        'adapter en largeur
            Lg = CellW: HT = MemH * (Lg / MemW)
            L = 0: T = (CellH - HT) / 2
        Else
            Stop ' pas prévu ?
        End If
 
        .LockAspectRatio = False ' proportions d'origine lorsque vous la redimensionnez
        .Top = Range(Ad).Top + 2 ' haut de la cellule
        .Left = Range(Ad).Left + 2 ' gauche de la cellule
        .Height = CellH - 4
        .Width = CellW - 4 ' largeur des cellules fusionnées
 
End With
Sh.Fill.UserPicture ficimg
ActiveCell.Offset(0, 1).Select
 
 
'With ficimg.Select
 
'    SELECTION.ShapeRange.Height = 141.7322834646
'    SELECTION.ShapeRange.Fill.Visible = msoFalse
'    SELECTION.ShapeRange.Line.Visible = msoFalse
'End With
 
Call compress
End Sub
Sub Vue_complementaire()
 
Dim strImage As String
Dim Sh As Shape
 
Dim ficimg As String, Ad As String
Dim MemW As Long, MemH As Long, T As Integer, L As Integer
Dim Lg As Integer, HT As Integer, RatioCell As Single
Dim CellH As Long, CellW As Long, RatioHz As Single, RatioVt As Single
Ad = SELECTION.Address
    CellH = SELECTION.Height
    CellW = SELECTION.Width
 
 
 
ficimg = Application.GetOpenFilename(".jpg,*.jpg", , "Choisissez l'image") ' choix nom du fichier
    If ficimg = "Faux" Then Exit Sub
 
 
Set Sh = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 300, 200, 167, 130)
 
With Sh
    .Select
    SELECTION.ShapeRange.Line.Visible = msoFalse
    SELECTION.ShapeRange.Shadow.Visible = msoFalse
    SELECTION.ShapeRange.AlternativeText = ficimg
 
        .LockAspectRatio = False ' proportions d'origine lorsque vous la redimensionnez
        .Top = Range(Ad).Top + 1 ' haut de la cellule
        .Left = Range(Ad).Left + 1 ' gauche de la cellule
        .Height = 132
        .Width = 174 ' largeur des cellules fusionnées
 
 
End With
 
Sh.Fill.UserPicture ficimg
Call compress
 
ActiveCell.Offset(0, 1).Select
End Sub