IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Problème rotation image non voulue [XL-365]


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti Avatar de hoyohoyo
    Profil pro
    Directeur de projet
    Inscrit en
    Août 2006
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Directeur de projet

    Informations forums :
    Inscription : Août 2006
    Messages : 40
    Par défaut Problème rotation image non voulue
    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

  2. #2
    Membre émérite

    Homme Profil pro
    linux, pascal, HTML
    Inscrit en
    Mars 2002
    Messages
    649
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 76
    Localisation : Belgique

    Informations professionnelles :
    Activité : linux, pascal, HTML
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2002
    Messages : 649
    Billets dans le blog
    1
    Par défaut
    Bonjour,
    ces informations sont dans les métadonnées de la photo.
    Sous linux j'utilise un programme qui porte le nom du format :EXIF
    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
    exif P1000701.JPG
    Marqueurs EXIF dans'P1000701.JPG' (ordre des octets 'Intel') :
    --------------------+----------------------------------------------------------
    Marqueur            |Valeur
    --------------------+----------------------------------------------------------
    Fabricant           |Panasonic
    Modèle              |DMC-TZ100
    Orientation         |En haut à gauche
    X-Resolution        |180
    Y-Resolution        |180
    Unité de la résoluti|pouces
    Logiciel            |Ver.1.2  
    Date et heure       |2017:11:06 11:40:32
    Positionnement YCbCr|Co-sited
    PRINT Image Matching|208 octets de données indéfinies
    Compression         |Compression JPEG
    Image portrait:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    exif P1000708.JPG| grep Orientation
    Orientation         |Right-top
    Orientation         |Right-top
    Image paysage :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    exif P1000701.JPG| grep Orientation
    Orientation         |En haut à gauche
    Orientation         |En haut à gauche
    Cela ne résout pas ton problème directement mais pourrait te donner une piste

  3. #3
    Membre émérite

    Homme Profil pro
    linux, pascal, HTML
    Inscrit en
    Mars 2002
    Messages
    649
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 76
    Localisation : Belgique

    Informations professionnelles :
    Activité : linux, pascal, HTML
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2002
    Messages : 649
    Billets dans le blog
    1
    Par défaut extraire les EXIF
    Re bonjour
    Je viens de tomber sur une page où on trouve cette macro
    une routine pour extraire les Exifs Tags
    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
     Sub LireExifTags()
    Dim det_Headers(355)
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace("C:\Img\")
    Workbooks(1).Sheets(1).Activate
    For i = 0 To 355
    det_Headers(i) = objFolder.GetDetailsOf(objFolder.Items, i)
    ActiveSheet.Cells(1, i + 1) = det_Headers(i)
    Next
    Workbooks(1).Sheets(1).Activate
    j = 2
    For Each strFileName In objFolder.Items
    For i = 0 To 355
    Sheets(1).Cells(j, i + 1).Value = objFolder.GetDetailsOf(strFileName, i)
    Next
      j = j + 1
    Next
    End Sub

  4. #4
    Membre émérite

    Homme Profil pro
    linux, pascal, HTML
    Inscrit en
    Mars 2002
    Messages
    649
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 76
    Localisation : Belgique

    Informations professionnelles :
    Activité : linux, pascal, HTML
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2002
    Messages : 649
    Billets dans le blog
    1
    Par défaut
    encore mieux ! sur le site de Developpez.net
    https://arkham46.developpez.com/arti...clgdiplusexif/

  5. #5
    Membre averti Avatar de hoyohoyo
    Profil pro
    Directeur de projet
    Inscrit en
    Août 2006
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Directeur de projet

    Informations forums :
    Inscription : Août 2006
    Messages : 40
    Par défaut
    Bonjour,

    Merci pour les piste, mais ça ne va pas du tout m'aider, je m'y connais pas du tout, je vais voir avec l'informaticien de l'entreprise s'il comprend à ce que tu m'as envoyer
    A par cliquer sur lancer macro je ne vais pas plus loin

  6. #6
    Inactif  

    Homme Profil pro
    cuisiniste
    Inscrit en
    Avril 2009
    Messages
    15 374
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : cuisiniste
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2009
    Messages : 15 374
    Billets dans le blog
    8
    Par défaut re
    Bonjour
    j'avoue que je pige pas très bien
    c'est quoi cette (usine a gaz) pour insérer une image et la caller dans un range bien définie

    pour la rotation si les données exif ne te disent rien c'est mort vba ne devinera jamais le sens de l'image

    je sais pas si c'est complètement dynamique mais si c'est un dossier constant d'images, ouvre les avec la visionneuse Windows tu a les outils pour les retourner c'est sauvegarder automatiquement tes photos seront dans le bons sens

    pour l'insertion d'image addpicture ou picture insert fait très bien l'affaire
    mes fichiers dans les contributions:
    mail avec CDO en vba et mail avec CDO en vbs dans un HTA
    survol des bouton dans userform
    prendre un cliché d'un range

    si ton problème est résolu n'oublie pas de pointer : : ça peut servir aux autres
    et n'oublie pas de voter

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème rotation image
    Par mecha31 dans le forum Windev Mobile
    Réponses: 5
    Dernier message: 13/09/2012, 09h58
  2. problème rotation image avec pcolor
    Par aurélie42 dans le forum Images
    Réponses: 2
    Dernier message: 27/06/2012, 13h33
  3. Problème lien référencé non voulu
    Par thibotus01 dans le forum Général Conception Web
    Réponses: 14
    Dernier message: 20/08/2009, 18h03
  4. Problème d'execution non voulue au démarrage
    Par adidas40 dans le forum wxPython
    Réponses: 0
    Dernier message: 22/04/2009, 13h25
  5. Réponses: 1
    Dernier message: 03/10/2007, 13h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo