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
|
Public Function TestWord()
Dim wdApp As Word.Application, wdDoc As Word.Document, wdPar As Word.Paragraph
Dim Texte As Word.Range, Titre As Word.Range
' Définition de Word
Set wdApp = CreateObject("Word.Application")
' Ouverture d'un nouveau document
Set wdDoc = wdApp.Documents.Add
(...)
Set wdPar = wdDoc.Paragraphs.Add
Set Titre = wdPar.Range
With Titre
.Bold = True
.Italic = False
.Font.Name = "Arial"
.Font.Size = "10"
.ParagraphFormat.Alignment = wdAlignParagraphLeft
End With
Titre.Collapse ' Obliger l'insertion au niveau du curseur
Titre.InsertBefore ("Essai de titre: ")
Set Titre = Nothing
Set Texte = wdPar.Range
With Texte
.Bold = False
.Italic = False
.Font.Name = "Arial"
.Font.Size = "10"
.ParagraphFormat.Alignment = wdAlignParagraphLeft
End With
Texte.Collapse
Texte.InsertAfter ("Essai de texte")
Set Texte = Nothing
Set wdPar = Nothing
(...)
' Fermeture du document et de l'application Word
wdDoc.SaveAs (CurrentProject.Path & "\test.doc")
wdDoc.Close
Set wdDoc = Nothing
wdApp.Quit
Set wdApp = Nothing |
Partager