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
|
Private Sub exportExcel_Click()
' Export des indicateurs commandes vers excel avec un onglet spécifique par indicateur
' Fichier excel créé avec indication dans le nom du fichier de la fourchette de dates choisies
'
Dim xlApp As Excel.Application
Dim xlsheet As Excel.Worksheet
Dim xlBook As Excel.Workbook
Dim i As Integer
Dim qry1 As String
Dim qry2 As String
Dim qry3 As String
Dim emplacement As String
Dim nomfichinit As String
Dim nomfich As String
Dim onglet As String
emplacement = "c:\bases access\Dev\test resultats\"
nomfichinit = "entrées commandes_" & datedeb & "_" & datefin
nomfich = nomfichinit
i = 2
FileSearch.lookin = emplacement
FileSearch.Filename = nomfich
FileSearch.filetype = msoFileTypeAllFiles
FileSearch.Searchsubfolders = False
While FileSearch.Execute
nomfich = nomfichinit & "v_" & i
i = i + 1
FileSearch.Filename = nomfich
Wend
If nomfich <> nomfichinit Then
MsgBox "Le fichier existait déja et a été recréé avec l'extension : " & Right(nomfich, 3)
End If
'exécution requetes et export dans onglets excel
qry1 = "qry_entcdes"
qry2 = "qry_entcdeslig"
qry3 = "qry_entcdesclts"
Set xlApp = CreateObject("Excel.Application")
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, qry1, (emplacement & nomfich), True, "cdes fermes"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, qry2, (emplacement & nomfich), True, "cdes lig"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, qry3, (emplacement & nomfich), True, "cdes par clients"
xlApp.Visible = True
xlApp.Workbooks.Open (emplacement & nomfich)
Set xlBook = xlApp.Workbooks.Open(emplacement & nomfich)
onglet = "cdes_fermes"
Set xlsheet = xlBook.sheets(onglet)
xlsheet.Activate
Call formatex
onglet = "cdes_lig"
Set xlsheet = xlBook.sheets(onglet)
xlsheet.Activate
Call formatex
onglet = "cdes_par_clients"
Set xlsheet = xlBook.sheets(onglet)
xlsheet.Activate
Call formatex
Set xlApp = Nothing
Set xlBook = Nothing
Set xlsheet = Nothing
End Sub |
Partager