Bonjour,
Je suis nouveau sur le forum. Je souhaite solliciter votre aide sur le sujet suivant.
Nous avons un outil qui nous génère des documents Word en fonction du contenu d'une base de donnée. Celui-ci formatte les paragraphe avec des noms de styles. Un template dont les styles ont été définis. Cependant la génération est un peu foireuse quand il s'agit de l'utilisation de style.
Les styles se présentent de la manière suivante:
Cependant la génération a tendance a créé des document en
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 1. Titre 1 (1) Enumeration level 1 (2) Enumeration level 1 - Enumeration level 2 a. Enumeration level 3 b. Enumeration level 3 - Enumeration level 4 - Enumeration level 4 (3) Enumeration level 1 (4) Enumeration level 1 - Enumeration level 2 a. Enumeration level 3 i. Enumeration level 5 - Enumeration level 6 a) Enumeration level 7 - Enumeration level 8 - Enumeration level 9 1.1. Titre 2 (1) Enumeration level 1 a. Enumeration level 3 b. Enumeration level 3 (2) Enumeration level 1 Annex A Annexe level 1 A.1 Annexe level 2 (1) Enumeration level 1 - Enumeration level 2 - Enumeration level 2 - Enumeration level 2 etc...
Il ne me semble pas qu'il y ait des problemes dans la définitions des styles et énumération dans le document modele/receptacle.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 1. Titre 1 (1) Enumeration level 1 (2) Enumeration level 1 a. Enumeration level 3 b. Enumeration level 3 (3) Enumeration level 1 (4) Enumeration level 1 a. Enumeration level 3 b. Enumeration level 3 2. Titre 1 (5) Enumeration level 1 a. Enumeration level 3 b. Enumeration level 3 (6) Enumeration level 1
Sachant que les document sont composés de milliers d'énumération et des dizaines de chapitres, il est compliqué de faire le re-démarrage manuellement.
J'ai créé un code en VBA pensant redémarrer les énumération a 1 apres chaque niveau de chapitre ou d'annexe
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 Public Const Enum_Lvl_1_name As String = "Enum_Lvl_1" Public Const Enum_Lvl_2_name As String = "Enum_Lvl_2" Public Const Enum_Lvl_3_name As String = "Enum_Lvl_3" Public Const Enum_Lvl_4_name As String = "Enum_Lvl_4" Public Const Enum_Lvl_5_name As String = "Enum_Lvl_5" Public Const Enum_Lvl_6_name As String = "Enum_Lvl_6" Public Const Enum_Lvl_7_name As String = "Enum_Lvl_7" Public Const Enum_Lvl_8_name As String = "Enum_Lvl_8" Public Const Enum_Lvl_9_name As String = "Enum_Lvl_9" Public Const Annex_Lvl_1_name As String = "Annex_Lvl_1" Public Const Annex_Lvl_2_name As String = "Annex_Lvl_2" Public Const Annex_Lvl_3_name As String = "Annex_Lvl_3" Public Const Annex_Lvl_4_name As String = "Annex_Lvl_4" Public Const Annex_Lvl_5_name As String = "Annex_Lvl_5" Public Const Annex_Lvl_6_name As String = "Annex_Lvl_6" Public Const Annex_Lvl_7_name As String = "Annex_Lvl_7" Public Const Annex_Lvl_8_name As String = "Annex_Lvl_8" Public Const Annex_Lvl_9_name As String = "Annex_Lvl_9" Public Const LIST_ENUM As String = "ENUM_LIST" Sub Main_FixEnum_v4() Dim oDoc As Word.Document Dim oPara As Paragraph Dim oParaCurrent As Paragraph Dim oParaPrevious As Paragraph Dim Response As Integer Dim FlagTrackChange As Boolean Set oDoc = ActiveDocument Set oParaCurrent = Nothing Set oParaPrevious = Nothing 'Optimize execution FlagTrackChange = oDoc.TrackRevisions oDoc.TrackRevisions = False Options.CheckGrammarAsYouType = False Options.CheckSpellingAsYouType = False Options.Pagination = False Application.ScreenUpdating = False ParagraphCount = oDoc.Paragraphs.Count ParagraphProgress = 0 For Each oPara In oDoc.Paragraphs Set oParaPrevious = oParaCurrent Set oParaCurrent = oPara If oParaPrevious Is Nothing Then 'Management of first paragraph without a previous paragraph ' Nothing Else If isHeading(oParaPrevious.Style.NameLocal, oDoc) = True And oParaCurrent.Style = Enum_Lvl_1_name Then oPara.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:=ListGalleries(wdOutlineNumberGallery).ListTemplates(1), ContinuePreviousList:=False, ApplyTo:=wdListApplyToWholeList Else 'Nothing End If End If Next oPara Options.CheckGrammarAsYouType = False Options.CheckSpellingAsYouType = False Options.Pagination = True oDoc.TrackRevisions = FlagTrackChange Application.ScreenUpdating = True Set oPara = Nothing Set oParaCurrent = Nothing Set oParaPrevious = Nothing Set oDoc = Nothing Response = MsgBox("Complete !", vbOKOnly)Cependant le résultat donne quelque chose comme:
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 Private Function isHeading(ByRef sParaStyle As String, ByRef oDoc As Word.Document) As Boolean 'Retrieve the local name of Style ( avoid the case where French / English style name are different) If sParaStyle = oDoc.Styles(wdStyleHeading1).NameLocal Then isHeading = True ElseIf sParaStyle = oDoc.Styles(wdStyleHeading2).NameLocal Then isHeading = True ElseIf sParaStyle = oDoc.Styles(wdStyleHeading3).NameLocal Then isHeading = True ElseIf sParaStyle = oDoc.Styles(wdStyleHeading4).NameLocal Then isHeading = True ElseIf sParaStyle = oDoc.Styles(wdStyleHeading5).NameLocal Then isHeading = True ElseIf sParaStyle = oDoc.Styles(wdStyleHeading6).NameLocal Then isHeading = True ElseIf sParaStyle = oDoc.Styles(wdStyleHeading7).NameLocal Then isHeading = True ElseIf sParaStyle = oDoc.Styles(wdStyleHeading8).NameLocal Then isHeading = True ElseIf sParaStyle = oDoc.Styles(wdStyleHeading9).NameLocal Then isHeading = True ElseIf sParaStyle = Annex_Lvl_1_name Then isHeading = True ElseIf sParaStyle = Annex_Lvl_2_name Then isHeading = True ElseIf sParaStyle = Annex_Lvl_3_name Then isHeading = True ElseIf sParaStyle = Annex_Lvl_4_name Then isHeading = True ElseIf sParaStyle = Annex_Lvl_5_name Then isHeading = True ElseIf sParaStyle = Annex_Lvl_6_name Then isHeading = True ElseIf sParaStyle = Annex_Lvl_7_name Then isHeading = True ElseIf sParaStyle = Annex_Lvl_8_name Then isHeading = True ElseIf sParaStyle = Annex_Lvl_9_name Then isHeading = True Else isHeading = False End If End Function
Je ne vois pas comment continuer la liste apres le titre pour avoir le résultat escomptés...
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
191. Titre 1 (1) Enumeration level 1 (2) Enumeration level 1 a. Enumeration level 3 b. Enumeration level 3 (3) Enumeration level 1 (4) Enumeration level 1 a. Enumeration level 3 b. Enumeration level 3 1.1 Titre 2 (1) Enumeration level 1 a. Enumeration level 3 b. Enumeration level 3 (5) Enumeration level 1 1.2. Titre 2 (1) Enumeration level 1 a. Enumeration level 3 b. Enumeration level 3 (6) Enumeration level 1
En cliquant sur la puce numérotée j'ai l'impression que cela a créé "3 listes" une bleu, une rouge et une verte. Cependant, je ne vois pas comment dire que la liste bleu se trouve entre deux titre, la liste verte entre deux titres, etc..
Est ce que vous auriez une piste ?




Répondre avec citation


Partager