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
| Sub publi_convention_attestation()
'Nécessite d'activer la référence "Microsoft Word xx.x Object Library"
Dim docWord As Word.Document
Dim appWord As Word.Application
Dim NomBase As String
Dim convention As Variant
Set convention = Sheets("Publipostage attestation")
Dim nom As Variant
nom = Sheets("Base à remplir").Range("C18").Value
Dim module As Variant
module = Sheets("Base à remplir").Range("C12").Value
'Chemin = activeworksheets
NomBase = "J:\Publipostages\Matrice RB.xlsm"
'_______________________________________________________________________________
'Ouverture Word
Application.ScreenUpdating = False
Set appWord = New Word.Application
appWord.Visible = True
'Ouverture Attestation Word
Set docWord = appWord.Documents.Open("J:\Publipostages\Attestation RB - modèle.doc")
nom = Sheets("Base à remplir").Range("C18").Value
'fonctionnalité de publipostage pour le document spécifié
With docWord.MailMerge
'Ouvre la base de données
.OpenDataSource Name:=NomBase, _
SQLStatement:="SELECT * FROM [Publipostage attestation$]"
'Spécifie la fusion
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
'Prend en compte l'ensemble des enregistrements
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
'Exécute l'opération de publipostage
.Execute Pause:=False
End With
'Sauvegarde le fichier sous un nom particulier'
ActiveDocument.SaveAs Filename:= _
"J:\ATTESTATIONS\Attestation " & module & " - " & nom & ".docx" _
, FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False
'ActiveWindow.Close
Application.ScreenUpdating = True
'Fermeture de Word
docWord.Close False
Set docWord = Nothing 'rajouté'
'_______________________________________________________________________________
'Ouverture Convention Word
Set docWord = appWord.Documents.Open("J:\Publipostages\Convention RB - modèle.doc")
nom = Sheets("Base à remplir").Range("C18").Value
'fonctionnalité de publipostage pour le document spécifié
With docWord.MailMerge
'Ouvre la base de données
.OpenDataSource Name:=NomBase, _
SQLStatement:="SELECT * FROM [Publipostage Conventions$]"
'Spécifie la fusion
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
'Prend en compte l'ensemble des enregistrements
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
'Exécute l'opération de publipostage
.Execute Pause:=False
End With
'Sauvegarde le fichier sous un nom particulier'
ActiveDocument.SaveAs Filename:= _
"J:\CONVENTIONS\Convention " & module & " - " & nom & ".docx" _
, FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False
'ActiveWindow.Close
Application.ScreenUpdating = True
'Fermeture du document Word
docWord.Close False
Set docWord = Nothing 'rajouté"
appWord.Quit
Set appWord = Nothing 'rajouté'
End Sub |
Partager