Bonjour,
novice en vba (depuis hier), voici ma question et son contexte.
je veux générer un rapport Word à partir d’un tableau excel, et ne parviens pas à mettre en forme le texte qui sera dans le fichier word.
Le tableau est du type
A B C blabla 224 aaa38 blibli 236 bbb37
La sortie attendue est sous word :
Mon souci est la mise en forme des ‘A’, ‘B’ et ‘C’. Comment faire pour que ceux-ci soient en gras + bleu + centré ?(page1)
A
Blabla
B
224
C
Aaa38
(page2)
A
Blibli
B
236
C
Bbb37
ci-dessous mon code actuel (qui nécessite d’ailleurs peut-être un peu d’optimisation).
--
--
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 Sub TestEcrireTemplate() Dim MonWord As Object Set MonWord = CreateObject("Word.Application") ' Création d'un nouveau document : MonWord.Documents.Add ' Ecriture du texte dans ce nouveau document : Dim nLine As Integer Dim nColumn As Integer Dim strValueTitle As String Dim strValueSpecificProject As String Dim nMaxLine As Integer Dim nMaxColumn As Integer 'A MODIFIER PAR UN COUNT nMaxLine = 3 nMaxColumn = 4 For nLine = 2 To nMaxLine For nColumn = 1 To nMaxColumn 'read the value from the cell strValueTitle = Cells(1, nColumn) 'Format the value 'write the value to the document MonWord.Selection.TypeText Text:=strValueTitle ' ICI : MISE EN FORME QUI NE FONCTIONNE PAS 'With Text ' .Font.Bold = True 'End With 'move to the next line MonWord.Selection.TypeParagraph 'read the value from the cell strValueSpecificProject = Cells(nLine, nColumn) 'write the value to the document MonWord.Selection.TypeText Text:=strValueSpecificProject 'move to the next line MonWord.Selection.TypeParagraph Next nColumn 'move to next page MonWord.Selection.InsertBreak Next nLine ' Sauvegarde de ce document ainsi créé : MonWord.ActiveDocument.SaveAs "~\test.doc" ' Fermeture de ce document : MonWord.ActiveDocument.Close Set MonWord = Nothing End Sub
Merci de votre aide !
Pierre
Partager