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 :

PaperSize = xlPaperUser (définir un format personnalisé ?)


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    118
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : Belgique

    Informations forums :
    Inscription : Juillet 2004
    Messages : 118
    Par défaut PaperSize = xlPaperUser (définir un format personnalisé ?)
    Bonjour,

    Pour résumé, je dois sauver 2 plages de cellules au format jpg.
    J'utilise pour celà PDFCreator (car en passant par un graphique on est limité à une image de 1238x1238) en modifiant le format de sortie.

    Le petit problème que j'ai est que ces plages de cellules n'ont pas un format de sortie "standard" style A4, A3,... et si je fais ajuster à la page, ça ne convient pas non plus...

    Pour être plus clair, voici ce que j'obtiens avec mon code actuel :
    En partant du tableau à gauche, je sélectionne tour à tour les 2 plages de cellules et les sauve en jpeg via PDFCreator. Seulement le format est pour l'instant forcé en A3 et l'image est donc ajustée ; elles ne sont donc pas de même largeur. De plus, les images sont pivotées de -90° ?!??

    => image Reel.gif en pièce jointe

    Et ce que je voudrais, ce sont 2 images de largeur identique (la hauteur étant bien sur différente) et qui soient bien orientées...

    => image Voulu.gif en pièce jointe...


    J'ai donc cherché du côté du code pour PDFCreator, mais pas grand chose (même dans l'aide de PDFCreator).

    Je me suis donc dit : "Pourquoi pas modifier le PageSetup de la page avant de passer par PDFCreator ?"

    J'ai donc ça:
    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
    With ActiveWorkbook.Worksheets("Planning Journalier").PageSetup
        'Définit la zone d'impression pour une plage de cellules.
        .PrintArea = Range("A2:V34").Address
        'Mise en page: définit les marges
        .LeftMargin = Application.InchesToPoints(0.5)
        .RightMargin = Application.InchesToPoints(0.75)
        .TopMargin = Application.InchesToPoints(1.5)
        .BottomMargin = Application.InchesToPoints(1)
        .HeaderMargin = Application.InchesToPoints(0.5)
        .FooterMargin = Application.InchesToPoints(0.5)
        .Zoom = False
        .FitToPagesWide = 1 'adapter la zone d'impression à une seule feuille
        .FitToPagesTall = 1 'adapter la zone d'impression à une seule feuille
        .CenterHorizontally = True
        .CenterVertically = True
        .Orientation = xlLandscape 'xlPortrait
        .PaperSize = xlPaperA3 'xlPaperUser 'xlPaperA3
      End With
    Et c'est le dernier point où je bloque... pas moyen de trouver comment définir un taille "xlPaperUser" ?? une idée ?? je suis preneur

    merci
    Greg


    pour info, le code complet :
    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
    Private Sub CommandBtCreerImage_Click()
      Dim nomfichier, rep, repdate, corpsmessage, oldprinter As String
      Dim PDFCreator1 As PDFCreator.clsPDFCreator
      Dim FichierSource, FichierDestination
      oldprinter = ActivePrinter 'On va mettre en mémoire dans une variable le nom de l'imprimante par défaut
      rep = "C:\Documents and Settings\gregoire\Mes documents\Divers\PlanningPersonnel"
      repdate = rep & "\" & Format(Now, "yyyymmdd")
      If Dir(repdate, vbDirectory) = "" Then
           MkDir repdate 'on crée le répertoire s'il n'existe pas...
      Else
           'MsgBox "Le répertoire existe"
      End If
     
      ActiveWorkbook.Worksheets("Planning Journalier").Range("F2").Value = ""
      'ActiveWorkbook.Worksheets("Planning Journalier").PageSetup.PrintArea = Range("A2:V34").Address
      With ActiveWorkbook.Worksheets("Planning Journalier").PageSetup
        'Définit la zone d'impression pour une plage de cellules.
        .PrintArea = Range("A2:V34").Address
        'Mise en page: définit les marges
        .LeftMargin = Application.InchesToPoints(0.5)
        .RightMargin = Application.InchesToPoints(0.75)
        .TopMargin = Application.InchesToPoints(1.5)
        .BottomMargin = Application.InchesToPoints(1)
        .HeaderMargin = Application.InchesToPoints(0.5)
        .FooterMargin = Application.InchesToPoints(0.5)
        .Zoom = False
        .FitToPagesWide = 1 'adapter la zone d'impression à une seule feuille
        .FitToPagesTall = 1 'adapter la zone d'impression à une seule feuille
        .CenterHorizontally = True
        .CenterVertically = True
        .Orientation = xlLandscape 'xlPortrait
        .PaperSize = xlPaperA3 'xlPaperUser 'xlPaperA3
      End With
      Set PDFCreator1 = New PDFCreator.clsPDFCreator
      If PDFCreator1.cStart("/NoProcessingAtStartup") = False Then
          'creation d'un fichier de log
      End If
      nomfichier = "PlanningRoto_" & Format(Now, "yyyy-mm-dd") & ".jpg"
      With PDFCreator1
          .cVisible = True
          If .cStart("/NoProcessingAtStartup") = False Then
             If .cStart("/NoProcessingAtStartup", True) = False Then
                 MsgBox "Can't initialize PDFCreator.", vbCritical + vbOKOnly, "PrtPDFCreator"
                 Exit Sub
             End If
             ' L'imprimante est occupée
             .cVisible = True
          End If
          .cOption("UseAutosave") = 1
          .cOption("UseAutosaveDirectory") = 1
          .cOption("AutoSaveDirectory") = repdate
          .cOption("AutoSaveFilename") = nomfichier
          .cOption("AutosaveFormat") = 2 '   0=PDF, 1=Png, 2=jpg, 3=bmp, 4=pcx, 5=tif, 6=ps, 7=eps, 8=txt
          .cOption("PDFGeneralAutorotate") = 0
     
          .cClearCache
          .cDefaultPrinter = "PDFCreator"
      End With
      ActiveWorkbook.Worksheets("Planning Journalier").PrintOut Copies:=1, ActivePrinter:="PDFCreator"
      Do Until PDFCreator1.cCountOfPrintjobs = 1
          DoEvents
          Sleep 1000
      Loop
      PDFCreator1.cPrinterStop = False
      Do Until PDFCreator1.cCountOfPrintjobs < 1
          DoEvents
          Sleep 1000
      Loop
      'on fait une copie de l'image qu'on vient de créer
      FichierSource = repdate & "\" & nomfichier
      FichierDestination = rep & "\PlanningRoto.jpg"
      'MsgBox (FichierSource & " -> " & FichierDestination)
      FileCopy FichierSource, FichierDestination
     
      ActiveWorkbook.Worksheets("Planning Journalier").Range("F2").Value = ""
      'ActiveWorkbook.Worksheets("Planning Journalier").PageSetup.PrintArea = Range("A35:V94").Address
      With ActiveWorkbook.Worksheets("Planning Journalier").PageSetup
        'Définit la zone d'impression pour une plage de cellules.
        .PrintArea = Range("A35:V94").Address
        'Mise en page: définit les marges
        .LeftMargin = Application.InchesToPoints(0.5)
        .RightMargin = Application.InchesToPoints(0.75)
        .TopMargin = Application.InchesToPoints(1.5)
        .BottomMargin = Application.InchesToPoints(1)
        .HeaderMargin = Application.InchesToPoints(0.5)
        .FooterMargin = Application.InchesToPoints(0.5)
        .Zoom = False
        .FitToPagesWide = 1 'adapter la zone d'impression à une seule feuille
        .FitToPagesTall = 1 'adapter la zone d'impression à une seule feuille
        .CenterHorizontally = True
        .CenterVertically = True
        .Orientation = xlLandscape 'xlPortrait
        .PaperSize = xlPaperA3 'xlPaperUser (420, 360)  'xlPaperA3
      End With
      'Set PDFCreator1 = New PDFCreator.clsPDFCreator
      If PDFCreator1.cStart("/NoProcessingAtStartup") = False Then
          'creation d'un fichier de log
      End If
      nomfichier = "PlanningCF_" & Format(Now, "yyyy-mm-dd") & ".jpg"
      With PDFCreator1
          .cVisible = True
          If .cStart("/NoProcessingAtStartup") = False Then
             If .cStart("/NoProcessingAtStartup", True) = False Then
                 MsgBox "Can't initialize PDFCreator.", vbCritical + vbOKOnly, "PrtPDFCreator"
                 Exit Sub
             End If
             ' L'imprimante est occupée
             .cVisible = True
          End If
          .cOption("UseAutosave") = 1
          .cOption("UseAutosaveDirectory") = 1
          .cOption("AutoSaveDirectory") = repdate
          .cOption("AutoSaveFilename") = nomfichier
          .cOption("AutosaveFormat") = 2 ' 0 = PDF
          .cOption("AutoRotate") = 0
          .cClearCache
          .cDefaultPrinter = "PDFCreator"
      End With
      ActiveWorkbook.Worksheets("Planning Journalier").PrintOut Copies:=1, ActivePrinter:="PDFCreator"
      Do Until PDFCreator1.cCountOfPrintjobs = 1
          DoEvents
          Sleep 1000
      Loop
      PDFCreator1.cPrinterStop = False
      Do Until PDFCreator1.cCountOfPrintjobs < 1
          DoEvents
          Sleep 1000
      Loop
      'on fait une copie de l'image qu'on vient de créer
      FichierSource = repdate & "\" & nomfichier
      FichierDestination = rep & "\PlanningCF.jpg"
      FileCopy FichierSource, FichierDestination
     
      PDFCreator1.cClose
      'MsgBox (oldprinter)
      ActivePrinter = oldprinter ' Change l'imprimante par défaut
    End Sub
    Images attachées Images attachées   

  2. #2
    Membre Expert
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    2 130
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 2 130
    Par défaut
    Salut greg778 et le forum
    En attendant une meilleure réponse, un palliatif
    - tu crées une nouvelle imprimante que tu paramètres avec les options qui t'interesses (taille papier, qualité, etc...)
    - avec une macro apprentissage, tu trouves le code pour la sélectionner.
    et tu auras un résultat qui devrait ressembler à ce que tu veux.
    A+
    Edit
    Me semble que le sujet a évolué pendant que je répondais
    dans les paramètres de mise en page, en apreçu, regardes ce que ça donne en :
    - définissant la zone d'impression
    - Orientation : portrait
    - ajuster à 1 page en largeur et tu efface de contenu de la case concernant la hauteur

    Si ton tableau peut être imprimé sur une page, pas besoinde passer en PDF
    fait des essais en manuel, pour trouver ce que tu dois utiliser en paramètres. une fois que ça marche correctement sur l'aperçu, tu peux passer par une macro apprentissage pour avoir ton code.
    A++

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    118
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : Belgique

    Informations forums :
    Inscription : Juillet 2004
    Messages : 118
    Par défaut
    Hello,

    quelques petites précisions :
    - Je passe par PDFCreator car j'ai besoin des sortir 2 images JPEG de mes tableaux... (comme illustré sur l'image Voulu.gif)
    - Le classeur sera placé sur plusieurs postes, dont les imprimantes installées sont différentes, d'où l'utilisation de PDFCreator.

    et pour répondre à ça :
    - définissant la zone d'impression => elle l'est (.PrintArea = Range("A2:V34").Addres)
    - Orientation : portrait => j'ai essayé, mais comme l'image n'a pas un format "standard", ça ne change pas grand chose.
    - ajuster à 1 page en largeur et tu efface de contenu de la case concernant la hauteur => même soucis que la remarque précédente.


    Comme je n'arrive pas à définir une taille précise dans "PageSetup", je cherche encore du côté des codes pour PDFCreator...

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    118
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : Belgique

    Informations forums :
    Inscription : Juillet 2004
    Messages : 118
    Par défaut
    Ce qui est bizarre, c'est qu'en choisissant le format de sortie PDF au lieu de JPEG, l'image n'est pas pivotée de -90°...

    Donc ça serait PDFCreator qui pivote obligatoirement les jpeg, puisque l'apperçu juste avant de créer l'image est bon.

    Je cherche plus d'options pour piloter PDFCreator...

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    118
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : Belgique

    Informations forums :
    Inscription : Juillet 2004
    Messages : 118
    Par défaut
    je pense encore à une autre solution... faire pivoter les fichiers images une fois créés depuis le code VB sous Excel...
    je cherche...

Discussions similaires

  1. [Vxi3] Définir format personnalisé sur la date
    Par Christophe29 dans le forum Webi
    Réponses: 6
    Dernier message: 11/03/2010, 13h36
  2. Utiliser un Formater personnalisé
    Par seareal dans le forum Struts 1
    Réponses: 1
    Dernier message: 13/12/2007, 16h46
  3. [C#][Cursor] Définir un curseur personnalisé pour un contrôle
    Par nicolas.pied dans le forum Windows Forms
    Réponses: 1
    Dernier message: 25/03/2007, 03h16
  4. Réponses: 2
    Dernier message: 03/11/2006, 09h34
  5. Réponses: 7
    Dernier message: 26/05/2006, 19h45

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