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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| Private Sub exporter()
Dim Msg, Style, Title, Help, Ctxt, Response
Msg = "Traitement terminé ,Voulez vous exporter les résultat vers Word ?" ' Définit le message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Définit les boutons.
Title = "exporter les résultats" ' Définit le titre.
' Affiche le message.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' L'utilisateur a choisi Oui.
Application.ScreenUpdating = False
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Set WordApp = New Word.Application
WordApp.Visible = True
Set WordDoc = WordApp.Documents.Add
'paramétrage des marges
With WordDoc.PageSetup
.LeftMargin = CentimetersToPoints(1)
.RightMargin = CentimetersToPoints(0.5)
.TopMargin = CentimetersToPoints(1.5)
.BottomMargin = CentimetersToPoints(2)
End With
Dim j, i, nb, k As Variant
Dim Cr As Integer
Cr = Worksheets(Sheets.Count).Cells(12, 2).End(xlToRight).Column
'//////////////////////////////copier la colonne 1
If Cr > 2 Then
Rows("25:25").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Clear
nb = Int(Cr / 16)
i = 26
For j = 1 To nb
Range("A1:A23").Copy
Range(Cells(i, 1), Cells(i + 23, 1)).PasteSpecial
i = i + 26
Next j
If (Cr - nb * 16) > 1 Then
Range("A1:A23").Copy
Range(Cells(i, 1), Cells(i + 23, 1)).PasteSpecial
End If
i = 26
x = 0
For j = 0 To nb - 1
Range(Cells(1, (16 * j + 2)), Cells(23, 16 * (j + 1) + 1)).Copy
Range("B" & i).Resize(23, 16).PasteSpecial
Range("A" & i).Resize(23, 17).Copy
WordApp.Selection.EndKey Unit:=wdStory
x = x + 1
WordApp.Selection.TypeText Text:="Tableau " & x
WordApp.Selection.PasteSpecial
WordApp.Selection.InsertBreak Type:=1
i = i + 26
Next j
If (Cr - nb * 16) > 1 Then
x = x + 1
Range(Cells(1, (16 * nb) + 2), Cells(23, Cr)).Copy
Range("B" & i).Resize(23, Cr - nb).PasteSpecial
Range("A" & i + 3).Select
k = Worksheets(Sheets.Count).Cells(i + 3, 1).End(xlToRight).Column
Range(Cells(i, 1), Cells(i + 23, k)).Copy
WordApp.Selection.EndKey Unit:=wdStory
WordApp.Selection.TypeText Text:="Tableau " & x
WordApp.Selection.PasteSpecial
WordApp.Selection.WholeStory
With WordApp.Selection.ParagraphFormat
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
With WordApp.Selection.ParagraphFormat
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
End If
WordApp.ActiveDocument.SaveAs "C:\temp\test.doc"
Application.CutCopyMode = False
Range("A1").Select
End If
End If
End Sub |
Partager