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 121 122 123 124 125 126 127
| Sub ExportGenerique(Z As MSFlexGrid)
Dim intI As Integer, IntC As Integer, IntCEx As Integer, IntIEx As Integer
Dim NbCol As Integer, NbRow As Integer
Dim TempString As String
On Error GoTo ErreurEx
Call InitEXCEL(UneErreur, TexteErreur)
If UneErreur Then
MsgBox "Excel n'a pas pu Etre Lancé" & vbCrLf & "Erreur : " & TexteErreur
Else
With Z
intI = 0
IntIEx = 0
NbCol = Z.Cols
NbRow = Z.Rows
intI = 0
While intI < NbRow
.Row = intI
IntC = 0
IntCEx = 1
While IntC < NbCol
.Col = IntC
ExcelObj.Cells(IntIEx + 2, IntCEx + 1).Value = .Text
If IntIEx = 0 Then
ExcelObj.Cells(IntIEx + 2, IntCEx + 1).Font.Size = 14
End If
IntC = IntC + 1
IntCEx = IntCEx + 1
Wend
intI = intI + 1
IntIEx = IntIEx + 1
Wend
ExcelObj.Range(IntituleCellule(2, 2) & ":" & IntituleCellule(IntCEx, IntIEx + 1)).Select
Call BordureTDT
ExcelObj.Range(IntituleCellule(1, 1) & ":" & IntituleCellule(2, 1)).Select
ExcelObj.Selection.Font.Size = 15
ExcelObj.Cells.Select
ExcelObj.Selection.HorizontalAlignment = xlCenter
ExcelObj.Selection.VerticalAlignment = xlCenter
ExcelObj.Selection.ColumnWidth = 2.57
ExcelObj.Selection.RowHeight = 15
ExcelObj.Selection.RowHeight = 30
ExcelObj.Cells.EntireColumn.AutoFit
Set ExcelObj = Nothing
End With
End If
Exit Sub
ErreurEx:
MsgBox "Erreur : " & Err.Description
End Sub
Sub InitEXCEL(Erreur As Boolean, Texte As String)
Err.Clear
On Error Resume Next
Dim xlApp As Excel.Application
Set xlApp = CreateObject("Excel.Application")
Set ExcelObj = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Erreur = True
Texte = Err.Description
Err.Clear
Else
Erreur = False
With ExcelObj
.Visible = True
.Workbooks.Add
.Sheets.Add
.Cells.Select
.Cells.Clear
End With
End If
End Sub
Function IntituleCellule(LaColonne As Integer, LaLigne As Integer) As String
Dim x As String
x = ""
If LaColonne <= 26 Then
x = Chr(LaColonne + 64)
ElseIf LaColonne <= 52 Then
x = "A"
x = x & Chr(LaColonne - 26 + 64)
Else
Exit Function
End If
x = x & LaLigne
IntituleCellule = x
End Function
Sub BordureTDT()
With ExcelObj
With .Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With .Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With .Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With .Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With .Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
.ActiveWindow.DisplayGridlines = False
End With
End Sub |
Partager