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 :

Export Word: centrer image/tableau/graphique


Sujet :

Macros et VBA Excel

  1. #1
    Membre confirmé
    Homme Profil pro
    dev
    Inscrit en
    Février 2015
    Messages
    80
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : dev

    Informations forums :
    Inscription : Février 2015
    Messages : 80
    Par défaut Export Word: centrer image/tableau/graphique
    Bonjour, le probleme est de centrer l'element exporté. Merci pour votre aide !

    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
    Function ExportTabRest(wsSheet As Worksheet, sChemin As String, rTab As Range, sTitre As String, bDimensionner As Boolean)
     
            Dim lNbTableaux As Long
     
            Set WdApp = Word.Application
            Set wdDoc = GetObject(sChemin)
            WdApp.Visible = True
     
            wsSheet.Select
            rTab.Copy
     
            WdApp.Selection.EndKey Unit:=wdStory, Extend:=wdMove
            WdApp.Selection.TypeParagraph
            WdApp.Selection.Paste
            'WdApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
            WdApp.Selection.InsertCaption Label:="Tableau", Title:=(" : " & sTitre), Position:=wdCaptionPositionBelow, _
            ExcludeLabel:=0
     
            lNbTableaux = wdDoc.Tables.Count
     
            Application.CutCopyMode = False
     
            If bDimensionner = True Then
            wdDoc.Tables(lNbTableaux).AutoFitBehavior wdAutoFitWindow
            End If
     
     
    End Function
     
    Function ExportTabAsPictureRest(wsSheet As Worksheet, sChemin As String, rTab As Range, sTitre As String)
     
            Dim lNbTableaux As Long
     
            Set WdApp = Word.Application
            Set wdDoc = GetObject(sChemin)
            WdApp.Visible = True
     
            wsSheet.Select
            rTab.CopyPicture
     
            WdApp.Selection.EndKey Unit:=wdStory, Extend:=wdMove
            WdApp.Selection.TypeParagraph
            WdApp.Selection.PasteSpecial Link:=False, DataType:=3, _
            Placement:=wdInLine, DisplayAsIcon:=False
            WdApp.Selection.TypeParagraph
            WdApp.Selection.InsertCaption Label:="Tableau", Title:=" : " & sTitre, Position:=wdCaptionPositionBelow, _
            ExcludeLabel:=0
            Application.CutCopyMode = False
     
     
    End Function
     
    Function ExportGraphRest(wsSheet As Worksheet, sChemin As String, sGraphNum As String, sTitre As String)
     
            Set WdApp = Word.Application
            Set wdDoc = GetObject(sChemin)
            WdApp.Visible = True
     
            wsSheet.Select
            wsSheet.ChartObjects("Graphique " & sGraphNum).Activate
            ActiveChart.ChartArea.Select
            ActiveChart.ChartArea.Copy
     
            WdApp.Selection.EndKey Unit:=wdStory, Extend:=wdMove
            WdApp.Selection.TypeParagraph
            WdApp.Selection.Paste
            WdApp.Selection.TypeParagraph
            WdApp.Selection.InsertCaption Label:="Figure", Title:=" - " & sTitre, Position:=wdCaptionPositionBelow, _
            ExcludeLabel:=0
            Application.CutCopyMode = False
     
     
    End Function

  2. #2
    Expert éminent Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Par défaut
    Tu oublies de marquer les autres post en Résolu (réponses sans suite)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    Function ExportGraphRest(wsSheet As Worksheet, sChemin As String, sGraphNum As String, sTitre As String)
    Dim wdDoc As Object
     
    Set wdDoc = GetObject(sChemin)
    wsSheet.ChartObjects("Graphique " & sGraphNum).Chart.CopyPicture
    With wdDoc.Parent.Selection
        .EndKey Unit:=6, Extend:=0    '6:wdStory  0:wdMove
        .TypeParagraph
        .ParagraphFormat.Alignment = 1    'wdAlignParagraphCenter
        .Paste
        .TypeParagraph
        .InsertCaption Label:="Figure", Title:=" - " & sTitre, Position:=1    'wdCaptionPositionBelow
    End With
    End Function

  3. #3
    Membre confirmé
    Homme Profil pro
    dev
    Inscrit en
    Février 2015
    Messages
    80
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : dev

    Informations forums :
    Inscription : Février 2015
    Messages : 80
    Par défaut
    Merci encore !

    ca marche bien pour les images, pour un tableau quelle serait la commande ?

    Une autre petite question...

    Comment centrer la legende aussi ?

    Merci !

    Hedi

  4. #4
    Expert éminent Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Par défaut
    Après le InsertCaption, ajoute cette ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
        .ParagraphFormat.Alignment = 1    'wdAlignParagraphCenter
    Tu devras comprendre ce qu'on te propose, c'est du vba Word en plus

  5. #5
    Membre confirmé
    Homme Profil pro
    dev
    Inscrit en
    Février 2015
    Messages
    80
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : dev

    Informations forums :
    Inscription : Février 2015
    Messages : 80
    Par défaut
    Merci, tout marche bien !

    Je comprends bien mais trouver tout ca dans l'aide ou sur internet c'est pas toujours gagné.

    A bientot mercatog

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

Discussions similaires

  1. Exporter tableau/graphique excel en image Word avec legende auto
    Par hedidev1 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 26/02/2015, 13h29
  2. [AC-2010] Exporter un sous formulaire "tableau" Access dans Word
    Par Goose- dans le forum VBA Access
    Réponses: 4
    Dernier message: 15/09/2012, 05h43
  3. Exportation tableau + Graphique
    Par Barbie123 dans le forum Macros et VBA Excel
    Réponses: 17
    Dernier message: 24/06/2009, 09h59
  4. Tableau graphique image
    Par lerorodu51 dans le forum WinDev
    Réponses: 1
    Dernier message: 19/05/2009, 16h45
  5. Réponses: 1
    Dernier message: 23/01/2009, 09h59

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