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
| Function fExportationExcel() As Boolean
Dim xlApp As Excel.Application, xlWkb As exel.Workbook, xlSheet As Excel.Worksheet, xlRange As Excel.Range
Dim sNomFich As String, sCheminResult As String
On Error GoTo lblErreur
sNomFich = "FICHIER.xls"
sCheminResult = Application.CurrentProject.Path & "\RESULTAT\"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, "REQUETE99", sCheminResult & sNomFich & "", True
'ouverture du fichier créé et application de la macro de mise en forme
Set xlApp = New Excel.Application
xlApp.Visible = True
Set xlWkb = xlApp.Workbooks.Open(sCheminResult & sNomFich & "")
Set xlSheet = xlWkb.Worksheets(1)
Set xlRange = xlSheet.UsedRange
'choix de la police, de la taille, mise en gas de la première ligne
xlRange.Font.Name = "ARIAL"
xlRange.Font.Size = 8
xlSheet.Rows("1:1").Font.Bold = True
'mise en forme automatique des largeurs de colonne
xlRange.EntireColumn.AutoFit
'vérouillage des volets à partir de la ligne2
xlSheet.Range("A2").Select
xlApp.ActiveWindow.FreezePanes = True
'centrage des valeurs dans la colonne B
xlSheet.Columns("B:B").HorizontalAlignment = xlCenter
'sauvegarde du classeur
xlWkb.Save
fExportationExcel = True
lblSortie:
Set xlRange = Nothing
Set xlSheet = Nothing
Set xlSheet = Nothing
Set xlWkb = Nothing
Set xlApp = Nothing
Exit Function
lblErreur:
fExportationExcel = False
GoTo lblSortie
End Function |
Partager