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
| Sub FiltrerMysqlESS()
Application.ScreenUpdating = False
' Connect to the database
Dim connected As Boolean
connected = Connect("xxxxx", "xxxxx", "xxxxxx,xxxxx", "xxxxxx")
If connected Then
Dim SQLForTempTab As String
Dim OPT As String
Dim EmpId As String
Dim Onglet As String
Dim Name As String
Dim sh As Worksheet
Name = "Feuil1"
OPT = ActiveSheet.Range("E4").Value
SQLForTempTab = "SELECT ReportD.Name, ReportD.Activity FROM BD1.dbo.ReportD ReportD WHERE (ReportD.WBS)='" & OPT & "';"
'ActiveWorkbook.Worksheets.Add After:=Sheets(Sheets.Count)
'Onglet = "Feuil1" & ActiveSheet.Name
Set sh = getWorkSheet(Name)
If sh Is Nothing Then
Set sh = GetNewWorksheet(Name)
If Not sh Is Nothing Then
MsgBox "Lafeuille a été créée"
Else
MsgBox "L'onglet existe déjà mais n'est pas une feuille de calcul"
End If
Else
MsgBox "La feuille existait déjà"
End If
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:="ODBC;DSN=MYSQL;", _
Destination:=Range("$A$1")).QueryTable
.CommandText = SQLForTempTab
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = Onglet
.Refresh BackgroundQuery:=False
End With
End If
End Sub |
Partager