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

VBA Word Discussion :

Enregistrer chaque page en tant que fichier PDF séparé avec des noms du doc [Toutes versions]


Sujet :

VBA Word

  1. #1
    Futur Membre du Club
    Femme Profil pro
    Chef de projet NTIC
    Inscrit en
    Février 2021
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 27
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : Enseignement

    Informations forums :
    Inscription : Février 2021
    Messages : 8
    Points : 6
    Points
    6
    Par défaut Enregistrer chaque page en tant que fichier PDF séparé avec des noms du doc
    Bonjour,

    J'ai un code qui me permet d'enregistrer les documents word microsoft en pdf séparément qui fonctionne très bien mais, lors de l'enregistrement du document word (avec plusieurs pages) en pdf j'ai : page_1.pdf, pour la première page du document, page_2.pdf pour la deuxième page du document ect....
    Et ce que je voudrai c'est avoir le texte qui est dans le paragraphe 18 en plus. Exemple : si dans la première page du doc au paragraphe 18, j'ai Mr Dupont, j'aimerai que lors de l'enregistrement en pdf j'ai : page_Mr Dupont_1.pdf
    Si dans la deuxième page au paragraphe 18, j'ai Mr ALEX, j'aimerai avoir : page_Mr ALEX_2.pdf
    Merci d'avance et bonne journée.

    Voici le code :
    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
    Sub SaveAsSeparatePDFs()
        Dim I As Long
        Dim xStr As String
        Dim xPathStr As Variant
        Dim xDictoryStr As String
        Dim xFileDlg As FileDialog
        Dim xStartPage, xEndPage As Long
        Dim xStartPageStr, xEndPageStr As String
        Set xFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
        If xFileDlg.Show <> -1 Then
            MsgBox "Please chose a valid directory", vbInformation, "Kutools for Word"
            Exit Sub
        End If
        xPathStr = xFileDlg.SelectedItems(1)
        xStartPageStr = InputBox("Begin saving PDFs starting with page __? " & vbNewLine & "(ex: 1)", "Kutools for Word")
        xEndPageStr = InputBox("Save PDFs until page __?" & vbNewLine & "(ex: 7)", "Kutools for Word")
        If Not (IsNumeric(xStartPageStr) And IsNumeric(xEndPageStr)) Then
            MsgBox "The enterng start page and end page should be number format", vbInformation, "Kutools for Word"
            Exit Sub
        End If
        xStartPage = CInt(xStartPageStr)
        xEndPage = CInt(xEndPageStr)
        If xStartPage > xEndPage Then
            MsgBox "The start page number can't be larger than end page", vbInformation, "Kutools for Word"
            Exit Sub
        End If
        If xEndPage > ActiveDocument.BuiltInDocumentProperties(wdPropertyPages) Then
            xEndPage = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
        End If
        For I = xStartPage To xEndPage
            ActiveDocument.ExportAsFixedFormat xPathStr & "\Page_" & I & ".pdf", _
            wdExportFormatPDF, False, wdExportOptimizeForPrint, wdExportFromTo, I, I, wdExportDocumentWithMarkup, _
            False, False, wdExportCreateHeadingBookmarks, True, False, False
        Next
    End Sub

  2. #2
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par Mikitars20 Voir le message
    Bonjour,

    Comment se présenterait un paragraphe 18 ?

  3. #3
    Futur Membre du Club
    Femme Profil pro
    Chef de projet NTIC
    Inscrit en
    Février 2021
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 27
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : Enseignement

    Informations forums :
    Inscription : Février 2021
    Messages : 8
    Points : 6
    Points
    6
    Par défaut
    Citation Envoyé par Eric KERGRESSE Voir le message
    Bonjour,

    Comment se présenterait un paragraphe 18 ?
    Bonjour,

    Mr ou Mme "prénom" "Nom"

    Voici un exemple en pièce jointe (j'ai du enregistrer sans macro pour pouvoir l'ajouter en pièce jointe)
    Fichiers attachés Fichiers attachés

  4. #4
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par Mikitars20 Voir le message

    Cette fonction récupère la chaîne complète :
    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
     
    Function NomPrenom(ByVal DocEnCours As Document, ByVal NumeroDePage As Integer) As String
     
    Dim I As Integer
     
        NomPrenom = ""
        With DocEnCours
             With .Tables(NumeroDePage).Range.Cells(2).Range.Paragraphs(17)
                  If Len(.Range.Text) > 1 Then
                     For I = 1 To Len(.Range.Text)
                         Select Case Mid(.Range.Text, I, 1)
                                Case "*", "?", ",", ".", "@", Chr(10), Chr(11), Chr(13)
     
                                Case Else
                                      NomPrenom = NomPrenom & Mid(.Range.Text, I, 1)
                         End Select
                     Next I
                  End If
            End With
        End With
     
    End Function

    Dans votre code principal :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
            For I = xStartPage To xEndPage
                NomPrenom2 = xPathStr & "\Page_" & NomPrenom(ActiveDocument, I) & "_" & I & ".pdf" '
                ActiveDocument.ExportAsFixedFormat NomPrenom2, _
                wdExportFormatPDF, False, wdExportOptimizeForPrint, wdExportFromTo, I, I, wdExportDocumentWithMarkup, _
                False, False, wdExportCreateHeadingBookmarks, True, False, False
            Next

  5. #5
    Futur Membre du Club
    Femme Profil pro
    Chef de projet NTIC
    Inscrit en
    Février 2021
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 27
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : Enseignement

    Informations forums :
    Inscription : Février 2021
    Messages : 8
    Points : 6
    Points
    6
    Par défaut
    Merci infiniment Eric. Je viens d'essayer et c'est exactement ce que je voulais.

    Dernière petite info, si jamais j'ai besoin d'enlever le Mr ou Mme et garder que le prénom et le nom, quel code devront nous appliquer .
    Je vous remercie .

  6. #6
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par Mikitars20 Voir le message
    Il faut utiliser la fonction Split :
    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
     
     
    Function NomPrenom(ByVal DocEnCours As Document, ByVal NumeroDePage As Integer) As String
     
    Dim NomPrenomTableau As Variant
     
        NomPrenom = ""
        With DocEnCours
                 With .Tables(NumeroDePage).Range.Cells(2).Range.Paragraphs(17)
                      NomPrenomTableau = Split(Mid(.Range.Text, 1, Len(.Range.Text) - 1), " ")
                      If UBound(NomPrenomTableau) >= 2 Then
                          NomPrenom = NomPrenomTableau(1) & " " & NomPrenomTableau(2)
                      End If
            End With
        End With
     
    End Function

  7. #7
    Futur Membre du Club
    Femme Profil pro
    Chef de projet NTIC
    Inscrit en
    Février 2021
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 27
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : Enseignement

    Informations forums :
    Inscription : Février 2021
    Messages : 8
    Points : 6
    Points
    6
    Par défaut
    Merci beaucoup

  8. #8
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par Mikitars20 Voir le message
    Cette variante répond au cas Jean Michel DUPONT :
    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
     
    Function NomPrenom(ByVal DocEnCours As Document, ByVal NumeroDePage As Integer) As String
     
    Dim I As Integer, CaractereDebut As Integer
    Dim NomPrenomTableau As Variant
     
        NomPrenom = ""
        With DocEnCours
             With .Tables(NumeroDePage).Range.Cells(2).Range.Paragraphs(17)
                  If Len(.Range.Text) > 1 Then
                     NomPrenomTableau = Split(.Range.Text, " ")
                     CaractereDebut = Len(NomPrenomTableau(0)) + 2
                     For I = CaractereDebut To Len(.Range.Text)
                         Select Case Mid(.Range.Text, I, 1)
                                Case "*", "?", ",", ".", "@", Chr(10), Chr(11), Chr(13)
     
                                Case Else
                                      NomPrenom = NomPrenom & Mid(.Range.Text, I, 1)
                         End Select
                     Next I
                     NomPrenom = Trim(NomPrenom)
                  End If
            End With
        End With
     
    End Function

  9. #9
    Futur Membre du Club
    Femme Profil pro
    Chef de projet NTIC
    Inscrit en
    Février 2021
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 27
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : Enseignement

    Informations forums :
    Inscription : Février 2021
    Messages : 8
    Points : 6
    Points
    6
    Par défaut
    Ah oui je n'y avais pas pensé. Merci beaucoup

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

Discussions similaires

  1. Réponses: 2
    Dernier message: 24/11/2020, 09h59
  2. [2012] Enregistrer un package en tant que => Pas d'emplacement du package
    Par olivierALLAIN dans le forum SSIS
    Réponses: 4
    Dernier message: 10/10/2014, 14h40
  3. Réponses: 9
    Dernier message: 24/05/2013, 15h09
  4. Réponses: 1
    Dernier message: 09/05/2012, 16h41
  5. lire le code html par le serveur en tant que fichier EXCEL
    Par john_wili dans le forum Struts 1
    Réponses: 2
    Dernier message: 14/01/2009, 15h59

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