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
| Option Compare Database
Function FichierExcel()
Dim xlapp As Excel.Application
Set xlapp = Excel.Application
dateextract = Date
Date1 = Left(dateextract, 2)
Date2 = Right(Left(dateextract, 5), 2)
Date3 = Right(dateextract, 4)
DateOK = Date1 & "-" & Date2 & "-" & Date3
NomfichierA = "Demandes Habilitations_" & DateOK
'Exportaton de la liste des demandes HB
DoCmd.RunSavedImportExport "Exportation-Liste HB"
Chemin = "C:\TEMP\"
Fichier = Chemin & "Liste Demandes Habilitations toutes.xlsx"
xlapp.Visible = True
xlapp.Workbooks.Open Fichier
xlapp.Sheets("Liste_Demandes_Habilitations_to").Name = "Demandes_Habilitations"
'Lancement du calcul des jours, heures, minutes ouvrées
Call JourOuvré
DisplayAlerts = False
' Mise en forme
xlapp.Cells.Select
With Selection.Font
.Name = "Calibri"
.Size = 9
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontMinor
End With
With Selection
.HorizontalAlignment = xlLeft
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Columns.AutoFit
Columns("B:F").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("A:A").Select
xlapp.Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:=".", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, _
1)), TrailingMinusNumbers:=True
Columns("A:A").EntireColumn.AutoFit
Columns("B:F").Select
Selection.Delete Shift:=xlToLeft
Cells.Select
xlapp.ActiveWorkbook.Worksheets("Demandes_Habilitations").Sort.SortFields.Clear
xlapp.ActiveWorkbook.Worksheets("Demandes_Habilitations").Sort.SortFields.Add Key:= _
Range("E2:E3769"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
xlapp.ActiveWorkbook.Worksheets("Demandes_Habilitations").Sort.SortFields.Add Key:= _
Range("A2:A3769"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("Demandes_Habilitations").Sort
.SetRange Range("A1:Z3769")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
xlapp.Range("A1").Select
'MISE EN FORME TABLEAU
'****************************************************************************************
'Besoin de déclarer ces variables pour récupérer le numéro de la dernière ligne sinon
'la mise en forme du tableau ne se fait pas sur toutes les lignes
Dim DernLigne As Long
Dim Ligne
DernLigne = Range("A" & Rows.Count).End(xlUp).Row
Ligne = "$A$1:$Z$" & DernLigne
'****************************************************************************************
xlapp.ActiveSheet.ListObjects.Add(xlSrcRange, Range(Ligne), , xlYes).Name = _
"Tableau1"
xlapp.Range("A1").Select
xlapp.Application.DisplayAlerts = False
xlapp.ActiveWorkbook.SaveAs FileName:="C:\TEMP\" + NomfichierA _
, Password:="", WriteResPassword:="", ReadOnlyRecommended:= _
False, CreateBackup:=False
'Envoi du fichier
''Call Envoi_Extraction
xlapp.Application.DisplayAlerts = True
xlapp.ActiveWorkbook.Close
xlapp.Quit
Kill ("c:\temp\Liste Demandes Habilitations toutes.xlsx")
Call Message
End Function |
Partager