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
|
Sub Valid()
'
' ImportsVar1 Macro
'
'Déclaration de la variable
Static NomServer As Variant
'Attribution d'une valeur à la variable
NomServer = "Win10dev"
MotDePasse = "*******"
NomBDD = "Projet test 1_Database01"
Colonne1 = "Chrono" 'Champs 1
Colonne2 = "TS"
Colonne3 = "Name"
Colonne4 = "Description"
Colonne5 = "Value"
'Affichage de la valeur de ma_variable dans une MsgBox
'MsgBox NomServer & ", " & NomBDD & ", " & Colonne1 & ", " & Colonne2 & ", " & Colonne3
'si presence d'un tableau, alors l'effacer, sinon, aller à la fin.
If Range("B7") = "" Then
GoTo Continuer
End If
EffacerTableau:
Range("Tableau_Lancer_la_requête_à_partir_de_win10dev[#Headers]").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Continuer:
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
"ODBC;DRIVER=ODBC Driver 13 for SQL Server;SERVER=NomServer;UID=admin;PWD=MotDePasse;Trusted_Connection=No;APP=2007 Microsoft Office system;WSID=NOMPC" _
), Array("POR045;")), Destination:=Range("$B$7")).QueryTable
.CommandText = Array( _
"SELECT TrendTable01.Chrono, TrendTable01.TS, TrendTable01.Name, TrendTable01.Description, TrendTable01.Value" & Chr(13) & "" & Chr(10) & "FROM ""Projet test 1_Database01"".dbo.TrendTable01 TrendTable01" _
)
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Tableau_Lancer_la_requête_à_partir_de_win10dev"
.Refresh BackgroundQuery:=False
End With
Columns("C:C").Select
Selection.NumberFormat = "dd/mm/yyyy hh:mm:ss"
Columns("B:B").Select
Selection.NumberFormat = "0"
Columns("B:B").EntireColumn.AutoFit
Columns("C:C").EntireColumn.AutoFit
Columns("E:E").EntireColumn.AutoFit
Columns("F:F").EntireColumn.AutoFit
Range("Tableau_Lancer_la_requête_à_partir_de_win10dev[#Headers]").Select
Range(Selection, Selection.End(xlDown)).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("A1").Select
End Sub |
Partager