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
| __________________________Dans mes fonctions______________________________
Public Function FeuilExiste(FeuilleAVerifier As String) As Boolean
'fonction qui vérifie si la "FeuilleAVerifier" existe dans le Classeur actif
On Error GoTo SiErreur
Dim Feuille
FeuilExiste = False
For Each Feuille In Sheets
If UCase(Feuille.Name) = UCase(FeuilleAVerifier) Then
FeuilExiste = True
Exit Function
End If
Next Feuille
Exit Function
SiErreur:
FeuilExiste = CVErr(xlErrNA)
End Function
_____________________________Dans mon SUB__________________
Call DELQUERY 'appel la fonction de suppression de requête
If FeuilExiste(OngletIMP) = True Then 'appel la fonction de controle de présente d'onglet
Application.DisplayAlerts = False
Sheets(OngletIMP).Delete 'supprime l'onglet
Application.DisplayAlerts = True
End If
'crée une requète sur la base du tableau souhaité
ActiveWorkbook.Queries.Add Name:="CONVERT Import SIGLE", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source =Excel.Workbook(File.Contents(" & Chr(34) & Linktab & Chr(34) & "), null, true)," & Chr(13) & "" & Chr(10) & " Feuil1_Sheet = Source{[Item=""Feuil1"",Kind=""Sheet""]}[Data]," & Chr(13) & "" & Chr(10) & " #""En-têtes promus"" = Table.PromoteHeaders(Feuil1_Sheet, [PromoteAllScalars=true])," & Chr(13) & "" & Chr(10) & " #""Type modifié"" = Table.TransformColumnTypes(#""En-têtes promus"",{{""Ty" & _
"pe batiment"", type text}, {""Trigramme"", type text}, {""Type de fait"", type text}, {""Num"", Int64.Type}, {""Annee"", Int64.Type}, {""Objet"", type text}, {""Delta nature de l'avarie"", type text}, {""Date msg FT"", type date}, {""Date DI"", type text}, {""Date TO"", type date}, {""Date fin de travaux"", type date}, {""Date msg cloture"", type date}, {""Descripti" & _
"f reparation"", type text}, {""Para golf msg"", type text}, {""Code SITINDIS"", type text}, {""Ref contrat"", type text}, {""Mot cle"", type text}, {""Intervenant"", type text}, {""Bigramme"", type text}, {""Libelle bigramme"", type text}, {""Description app integrant"", type text}, {""RFO en avarie"", type text}, {""Materiel"", type number}, {""Designation"", type " & _
"text}, {""Statut"", type text}, {""Site"", type any}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Type modifié"""
'crée un onglet nommé par la variable ongletIMP dans lequel la requète est envoyée
Sheets.Add(After:=Worksheets(Worksheets.Count)).Name = OngletIMP
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=CONVERT Import SIGLE;Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [CONVERT Import SIGLE]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = False
.ListObject.DisplayName = "Feuil1"
.Refresh BackgroundQuery:=False
End With
Sheets("Synthèse").Activate ' appel onglet synthese
Call MAJLISTE 'appelle macro
Call DELQUERY 'appel la fonction
If FeuilExiste(OngletIMP) = True Then 'appel la fonction de controle de présente d'onglet
Application.DisplayAlerts = False
Sheets(OngletIMP).Delete 'supprime l'onglet
Application.DisplayAlerts = True
End If |