Un petit code VBA qui génère 43 tableaux(3x3) dans un document word avec pour chacun des tableaux un autoformat (de 0 à 42) différent.

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
Sub autoformat_tableau()
'
' autoformat_tableau Macro
'
'
Dim WordApp As Object
Dim WordDoc, wdSel
 
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = True
Set WordDoc = WordApp.Documents.Add()
For num_autoformat = 0 To 42
Set wdSel = WordApp.Selection
Dim objTable As Object
Set objTable = WordDoc.Tables.Add(Range:=WordApp.Selection.Range, NumRows:=3, NumColumns:=3)
For x = 1 To 3
For y = 1 To 3
objTable.Columns(y).Width = 80 
objTable.Cell(x, y).Range.Text = "autoformat " & num_autoformat  
Next y
Next x
objTable.AutoFormat (num_autoformat)
Set objTable = Nothing
Set wdSel = Nothing
 
      ' insertion d'un retour
Set wdSel = WordApp.Selection
WordDoc.Bookmarks("\EndOfDoc").Select
Set wdSel = WordApp.Selection
wdSel.Text = Chr$(13)
WordDoc.Bookmarks("\EndOfDoc").Select
Set wdSel = Nothing
Next num_autoformat 
Set WordDoc = Nothing
Set WordApp = Nothing
 
End Sub